I have a rare usecase where I need to register multiple roots in my React Component and destroy them when the component unmounts. Obviously, it happens that I unmount a root when its rendering. I simulated that case by calling root.unmount()
right after root.render(...)
. in the following example: https://codesandbox.io/s/eager-grothendieck-h49eoo?file=%2Fsrc%2FApp.tsx
This results in the following warning:
Warning: Attempted to synchronously unmount a root while React was already rendering. React cannot finish unmounting the root until the current render has completed, which may lead to a race condition.
This warning implies to me that there is an async way to unmount a root, but I coouldn't find out how. Wrapping root.unmount()
in an async function (const unmount = async () => root.unmount()
) did not work. Any ideas? Am I getting something totally wrong here?