Skip to content

Commit

Permalink
improve instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed May 17, 2024
1 parent d788a9f commit 003ee08
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion examples/unnecessary-rerenders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function NameInput({
}) {
return (
<label>
Name: <input value={name} onChange={e => onNameChange(e.target.value)} />
Name:{' '}
<input value={name} onChange={e => onNameChange(e.currentTarget.value)} />
</label>
)
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/03.concurrent-rendering/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function App() {
const deferredText = useDeferredValue(text)
return (
<>
<input value={text} onChange={e => setText(e.target.value)} />
<input value={text} onChange={e => setText(e.currentTarget.value)} />
<SlowList text={deferredText} />
</>
)
Expand Down
6 changes: 4 additions & 2 deletions exercises/06.rerenders/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function NameInput({
}) {
return (
<label>
Name: <input value={name} onChange={e => onNameChange(e.target.value)} />
Name:{' '}
<input value={name} onChange={e => onNameChange(e.currentTarget.value)} />
</label>
)
}
Expand Down Expand Up @@ -125,7 +126,8 @@ const NameInput = memo(function NameInput({
}) {
return (
<label>
Name: <input value={name} onChange={e => onNameChange(e.target.value)} />
Name:{' '}
<input value={name} onChange={e => onNameChange(e.currentTarget.value)} />
</label>
)
})
Expand Down
2 changes: 1 addition & 1 deletion exercises/07.windowing/01.problem.virtualizer/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function CityChooser() {

const isPending = useSpinDelay(isTransitionPending)

// 🐨 create a ref here for HTMLDivElement
// 🐨 create a ref here for HTMLUListElement

// 🐨 create a rowVirtualizer with useVirtualizer from "@tanstack/react-virtual"
// - the count should be the length of the items
Expand Down
12 changes: 7 additions & 5 deletions exercises/07.windowing/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@ function MyListOfData({ items }) {
```tsx
// after
function MyListOfData({ items }) {
const listRef = useRef()
const parentRef = useRef<HTMLUListElement>(null)

const rowVirtualizer = useVirtualizer({
size: items.length,
getScrollElement: () => listRef.current,
count: cities.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 20,
})

return (
<ul ref={listRef} style={{ position: 'relative', height: 300 }}>
<ul ref={parentRef} style={{ position: 'relative', height: 300 }}>
<li style={{ height: `${rowVirtualizer.getTotalSize()}px` }} />
{rowVirtualizer.getVirtualItems().map(virtualItem => {
const { index, key, size, start } = virtualItem
const item = items[index]
if (!item) return null
const { index, key, size, start } = virtualItem
return (
<li
key={key}
Expand Down

0 comments on commit 003ee08

Please sign in to comment.