-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[v6] Cannot update a component from inside the function body of a different component. #7199
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
Comments
This is a new warning in React 16.13. I think the problem is we're issuing the effect of navigation in the Navigate component directly during rendering, not inside of a That alters the one single state value we maintain all the way up in Router: Hence, you hit the new warning that React now watches for. Again, I think the effect hook will help with this. |
I have this error appearing on withRouter-wrapped components using react-router-dom 5.1.2. The stack trace is ridiculous on this new warning but it appears thus far only where I have wrapped a functional component. |
react-router version: 6.0.0-alpha.2 With react 16.13.0, I get the same error message:
after upgrading to 16.13.1, the error message changes to:
screenshot: |
Hi guys, do you have any plan to have a look at this issue? |
See the linked PR: #7203 |
- Removes <Redirect> - Removes support for { redirectTo } in useRoutes() - Warns if navigate() is used during the initial render - Warns when <Navigate> is used on the initial render in <StaticRouter> This began as a discussion on GitHub (see #7203). Essentially we need to treat all navigation as a side effect, which means it needs to happen in a useEffect. If people need v5's <Redirect> functionality (when it was used in the route config inside a <Switch>), they either need to a) do the redirect on the server (the best solution) or b) render a <Navigate> on the initial render. However, (b) will only show the new route on the subsequent render. This should also eliminate warnings in the dev-experimental builds. Closes #7203 Fixes #7199
This was fixed in cbcd398 |
Will be released shortly in 6.0.0-alpha.3 👍 |
I'm tinkering with the v6 Alpha release and am running into the following console warning (see facebook/react#18178 for more information):
In v5, I had the following component:
Which is implemented via:
In v6, I have modified that component to be:
Which is implemented via:
When navigating to http://localhost:3000, I am properly redirected to http://localhost:3000/auth/login, but receive the aforementioned console warning.
Is there a different way I should be doing this with v6?
The text was updated successfully, but these errors were encountered: