From 587555991f97352c480373db6c4219e539b33ee5 Mon Sep 17 00:00:00 2001 From: Justin Jamison Date: Mon, 22 Jul 2024 21:05:42 -0600 Subject: [PATCH] Update index.tsx (#3) --- .../03.use-effect/02.problem.dependencies/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/exercises/03.use-effect/02.problem.dependencies/index.tsx b/exercises/03.use-effect/02.problem.dependencies/index.tsx index 1e2100b..0007f88 100644 --- a/exercises/03.use-effect/02.problem.dependencies/index.tsx +++ b/exercises/03.use-effect/02.problem.dependencies/index.tsx @@ -30,7 +30,7 @@ function useState(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 } } @@ -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() }