File tree 1 file changed +5
-3
lines changed
exercises/03.use-effect/01.problem.callback
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ let hookIndex = 0
13
13
const states : Array < [ any , ( newState : any ) => void ] > = [ ]
14
14
type EffectCallback = ( ) => void
15
15
// 🐨 make a variable called "effects" that's an array of objects with a callback property
16
+ // of the "EffectCallback" type we've defined above
16
17
17
18
function useState < State > ( initialState : State ) {
18
19
const id = hookIndex ++
@@ -28,8 +29,8 @@ function useState<State>(initialState: State) {
28
29
return states [ id ] as [ State , ( newState : State ) => void ]
29
30
}
30
31
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++"
33
34
34
35
function Counter ( ) {
35
36
const [ count , setCount ] = useState ( 0 )
@@ -66,7 +67,8 @@ function render(newPhase: Phase) {
66
67
// 🐨 wrap this in flushSync
67
68
appRoot . render ( < Counter /> )
68
69
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
70
72
}
71
73
72
74
render ( INITIALIZATION )
You can’t perform that action at this time.
0 commit comments