Skip to content

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