diff --git a/exercises/03.use-effect/01.problem.callback/index.tsx b/exercises/03.use-effect/01.problem.callback/index.tsx index a84f4e2..b72863e 100644 --- a/exercises/03.use-effect/01.problem.callback/index.tsx +++ b/exercises/03.use-effect/01.problem.callback/index.tsx @@ -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(initialState: State) { const id = hookIndex++ @@ -28,8 +29,8 @@ function useState(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) @@ -66,7 +67,8 @@ function render(newPhase: Phase) { // 🐨 wrap this in flushSync appRoot.render() - // 🐨 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)