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

Enqueue premature calls to useNavigate() in react-router-6 adapter #266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

afn
Copy link

@afn afn commented May 12, 2023

Prevent premature calls to useNavigate() from failing with "You should call navigate() in a React.useEffect(), not when your component is first rendered".

This warning happens even when navigate() is called from a useEffect(), because that effect is called before useNavigate's internal effect (parents' effects are invoked after children's effects).

To get around this, enqueue premature useNavigate() calls, and process the queue in a useEffect() (which is called after useNavigate's effect).

Fixes #211.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-router v6: warning You should call navigate() in a React.useEffect
1 participant