-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Bug: Unable to use unmountComponentAtNode
with unstable_createRoot
#21441
Comments
For the new roots you have the method directly on the root: const root = ReactDOM.unstable_createRoot(rootElement)
root.render(<App />);
root.unmount(); Does this work for you? Edit: react/packages/react-dom/src/client/ReactDOMLegacy.js Lines 345 to 354 in bd070eb
|
Something like that would've saved me 2 hours tonight 😄. Definitely a reasonable solution. I'd also say it should be on Reactjs.org: This is the other place I checked: |
Documentation for |
If you do The case where it doesn't is if you |
@gaearon It has an error message now :P. I think the situation you're talking about with the "render > unmount > render > unmount" is what I ran into. I was rendering a React component in Node-RED Dashboard which, if you update a node, re-runs your entrypoint in the dashboard. I was making sure to unmount before remounting, but it was still mounting and unmounting multiple times in the same page load. I later changed this whole system to render the React app into an iframe using the |
When calling
unmountComponentAtNode(document.getElementById('react-root'))
, it returnsfalse
.This would normally happen because I'm trying to unmount something that's not a React node, but that's not the case.
I'm using
unstable_createRoot
. If I userender
instead, it works fine.React version:
0.0.0-experimental-79740da4c
Steps To Reproduce
unstable_createRoot
.unmountComponentAtNode
.Link to code example: https://codesandbox.io/s/epic-leftpad-ih6ts?file=/src/index.js
The current behavior
Doesn't unmount the root React component.
The expected behavior
Should unmount the root React component.
The text was updated successfully, but these errors were encountered: