Skip to content

Commit

Permalink
Update index.tsx (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamisonj authored Jul 23, 2024
1 parent 0eefaf9 commit 5875559
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions exercises/03.use-effect/02.problem.dependencies/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function useState<State>(initialState: State) {
// 🐨 add an optional deps argument here
function useEffect(callback: EffectCallback) {
const id = hookIndex++
// 🐨 add deps to this object and prevDeps should be effects[id]?.deps
// 🐨 add deps and prevDeps to this object - prevDeps should be "effects[id]?.deps"
effects[id] = { callback }
}

Expand Down Expand Up @@ -74,10 +74,11 @@ function render(newPhase: Phase) {
for (const effect of effects) {
if (!effect) continue

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

effect.callback()
}
Expand Down

0 comments on commit 5875559

Please sign in to comment.