-
Notifications
You must be signed in to change notification settings - Fork 45.8k
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: Ref is set after componentDidMount (when mixing Class and Functional components) #29897
Comments
The behavior you're observing is a result of how React handles refs and the component lifecycle. Let's break down what's happening step by step: Rendering Phase: React begins rendering the App component. React mounts the children of the App component. After the rendering is complete, React assigns the ref and calls the refCallback. Order of Events Expected vs. Actual Behavior Copy code Copy code |
Hey @ifrost can you elaborate a little in which part of existing code/file you want this change ?? |
ClassComponent.componentDidMount is invoked before the refCallback is called. FunctionalComponent/useEffect callback is called after the refCallback is called.
I was expecting more consistency on timing but it seems it's kind of as you said - an expected behavior. |
React version: 18.2.0
Steps To Reproduce
Link to code example: https://playcode.io/1905766
The current behavior
Console logs:
ClassComponent
is mounted before reference is received. It's different if a functional component is used.The expected behavior
I'm not sure if this is expected behavior but I was expecting to receive a ref before components are mounted.
The text was updated successfully, but these errors were encountered: