Skip to content

Commit 0eefaf9

Browse files
jamisonjkentcdodds
andauthored
Update some code hints in Exercise 3-1 (#2)
Co-authored-by: Kent C. Dodds <[email protected]>
1 parent 33d8edd commit 0eefaf9

File tree

1 file changed

+5
-3
lines changed
  • exercises/03.use-effect/01.problem.callback

1 file changed

+5
-3
lines changed

exercises/03.use-effect/01.problem.callback/index.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let hookIndex = 0
1313
const states: Array<[any, (newState: any) => void]> = []
1414
type EffectCallback = () => void
1515
// 🐨 make a variable called "effects" that's an array of objects with a callback property
16+
// of the "EffectCallback" type we've defined above
1617

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

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

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

69-
// 🐨 add a for of loop for all the effects and call their callbacks.
70+
// 🐨 add a for of loop for all the effects and call their callbacks,
71+
// making sure to skip over any undefined effects
7072
}
7173

7274
render(INITIALIZATION)

0 commit comments

Comments
 (0)