-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Closed
Labels
Description
What version of React Router are you using?
6.3.0
Steps to Reproduce
Run the following code:
function Child(props) {
useEffect(() => {
props.wrappedNavigate('./otherRoute')
}, []);
return <></>
}
function Parent() {
const navigate = useNavigate();
const wrappedNavigate = (to) => {
navigate(to);
}
return <Child wrappedNavigate={wrappedNavigate} />
}
Expected Behavior
Navigate works and performs navigation.
Actual Behavior
You should call navigate() in a React.useEffect(), not when your component is first rendered.
is logged into the console.
This is due to the fact that the useEffect of the Child component is executed before the useEffect of the useNavigate, which causes invalid protection on navigation.