Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update some code hints in Exercise 3-1 #2

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions exercises/03.use-effect/01.problem.callback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let hookIndex = 0
const states: Array<[any, (newState: any) => void]> = []
type EffectCallback = () => void
// 🐨 make a variable called "effects" that's an array of objects with a callback property
// of the "EffectCallback" type we've defined on line 14 above
kentcdodds marked this conversation as resolved.
Show resolved Hide resolved

function useState<State>(initialState: State) {
const id = hookIndex++
Expand All @@ -28,8 +29,8 @@ function useState<State>(initialState: State) {
return states[id] as [State, (newState: State) => void]
}

// 🐨 create a useEffect function here that accepts a callback,
// gets the id from hookIndex++, and adds it to effects
// 🐨 create a useEffect function here that accepts an "EffectCallback" callback,
// and adds the callback to the effects array at the index "hookIndex++"

function Counter() {
const [count, setCount] = useState(0)
Expand Down Expand Up @@ -66,7 +67,8 @@ function render(newPhase: Phase) {
// 🐨 wrap this in flushSync
appRoot.render(<Counter />)

// 🐨 add a for of loop for all the effects and call their callbacks.
// 🐨 add a for of loop for all the effects and call their callbacks,
kentcdodds marked this conversation as resolved.
Show resolved Hide resolved
// making sure to skip over any undefined effects
}

render(INITIALIZATION)