Skip to content

Commit

Permalink
Update some code hints in Exercise 3-1 (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Kent C. Dodds <[email protected]>
  • Loading branch information
jamisonj and kentcdodds authored Jul 23, 2024
1 parent 33d8edd commit 0eefaf9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions exercises/03.use-effect/01.problem.callback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let hookIndex = 0
const states: Array<[any, (newState: any) => void]> = []
type EffectCallback = () => void
// 🐨 make a variable called "effects" that's an array of objects with a callback property
// of the "EffectCallback" type we've defined above

function useState<State>(initialState: State) {
const id = hookIndex++
Expand All @@ -28,8 +29,8 @@ function useState<State>(initialState: State) {
return states[id] as [State, (newState: State) => void]
}

// 🐨 create a useEffect function here that accepts a callback,
// gets the id from hookIndex++, and adds it to effects
// 🐨 create a useEffect function here that accepts an "EffectCallback" callback,
// and adds the callback to the effects array at the index "hookIndex++"

function Counter() {
const [count, setCount] = useState(0)
Expand Down Expand Up @@ -66,7 +67,8 @@ function render(newPhase: Phase) {
// 🐨 wrap this in flushSync
appRoot.render(<Counter />)

// 🐨 add a for of loop for all the effects and call their callbacks.
// 🐨 add a for of loop for all the effects and call their callbacks,
// making sure to skip over any undefined effects
}

render(INITIALIZATION)

0 comments on commit 0eefaf9

Please sign in to comment.