Skip to content

Commit 5875559

Browse files
authored
Update index.tsx (#3)
1 parent 0eefaf9 commit 5875559

File tree

1 file changed

+6
-5
lines changed
  • exercises/03.use-effect/02.problem.dependencies

1 file changed

+6
-5
lines changed

exercises/03.use-effect/02.problem.dependencies/index.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function useState<State>(initialState: State) {
3030
// 🐨 add an optional deps argument here
3131
function useEffect(callback: EffectCallback) {
3232
const id = hookIndex++
33-
// 🐨 add deps to this object and prevDeps should be effects[id]?.deps
33+
// 🐨 add deps and prevDeps to this object - prevDeps should be "effects[id]?.deps"
3434
effects[id] = { callback }
3535
}
3636

@@ -74,10 +74,11 @@ function render(newPhase: Phase) {
7474
for (const effect of effects) {
7575
if (!effect) continue
7676

77-
// 🐨 create a hasDepsChanged variable to determine whether the effect should be called
78-
// if the effect has no deps, hasDepsChanged should be true
79-
// if the effect does have deps, calculate whether any item in the dep array
80-
// is different from the corresponding item in the prevDeps array
77+
// 🐨 Create a "hasDepsChanged" variable to determine whether the effect should be called.
78+
// If the effect has no deps, "hasDepsChanged" should be true.
79+
// If the effect does have deps, "hasDepsChanged" should calculate whether any item
80+
// in the "deps" array is different from the corresponding item in the "prevDeps" array,
81+
// and return true if so, false otherwise.
8182

8283
effect.callback()
8384
}

0 commit comments

Comments
 (0)