Skip to content

Implement a flow custom navigator #11839

Answered by satya164
charlotteisambert asked this question in Q&A
Discussion options

You must be logged in to vote

In your example, you have this code:

setFlag(true)
goToNextStep()

When you cal setFlag(true), it will update state and trigger a re-render asynchronously since state updates are async in React. But here you're calling goToNextStep() synchronously, right after setFlag(true). By this time, the flag hasn't actually updated and the re-render hasn't happened. This would explain why you're going to step 3 instead of step 2.

So you'd somehow need to wait for the re-render to complete (e.g. some event in useEffect) before you can call goToNextStep(), e.g.

setFlag(true);
waitForFlag(goToNextStep);

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@charlotteisambert
Comment options

Answer selected by charlotteisambert
Comment options

You must be logged in to vote
1 reply
@oliviercperrier
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants