You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was digging into React internals and learning how it works under the hood. I came across an interesting behaviour in Effects -- where the Effects in children components are committed before their parent component.
(I made a small animation describing the traversal)
I understand that it is due to how React traverses the Fiber tree during the Commit phase (recursivelyTraversePassiveMountEffects), but it seems like it does confuse some people in
This is not a bug, but I think it would be helpful to have this documented, perhaps in the Caveats or the Troubleshooting section to avoid confusion around this "unexpected behaviour".
What do you think? :)
The text was updated successfully, but these errors were encountered:
It would also be nice to either provide an alternative for how to achieve the reverse behavior (parents first, children later) or assert that this is not possible
Uh oh!
There was an error while loading. Please reload this page.
Summary
Adding documentation to the useEffect page to note that Effects in children components are committed before their parent component
Page
https://react.dev/reference/react/useEffect
Details
Hi
I was digging into React internals and learning how it works under the hood. I came across an interesting behaviour in Effects -- where the Effects in children components are committed before their parent component.
For example:
The result in the console will be
(I made a small animation describing the traversal)
I understand that it is due to how React traverses the Fiber tree during the Commit phase (recursivelyTraversePassiveMountEffects), but it seems like it does confuse some people in
This is not a bug, but I think it would be helpful to have this documented, perhaps in the Caveats or the Troubleshooting section to avoid confusion around this "unexpected behaviour".
What do you think? :)
The text was updated successfully, but these errors were encountered: