diff --git a/src/content/learn/state-a-components-memory.md b/src/content/learn/state-a-components-memory.md index 75a1fd0b91e..92f407b1f7a 100644 --- a/src/content/learn/state-a-components-memory.md +++ b/src/content/learn/state-a-components-memory.md @@ -551,10 +551,6 @@ function useState(initialState) { return pair; } - // This is the first time we're rendering, - // so create a state pair and store it. - pair = [initialState, setState]; - function setState(nextState) { // When the user requests a state change, // put the new value into the pair. @@ -562,6 +558,10 @@ function useState(initialState) { updateDOM(); } + // This is the first time we're rendering, + // so create a state pair and store it. + pair = [initialState, setState]; + // Store the pair for future renders // and prepare for the next Hook call. componentHooks[currentHookIndex] = pair;