-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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: Certain uses of render props result in remounts on every render #18199
Comments
You were writing |
@jddxf So why does avoiding JSX seem to solve the problem? |
The non-jsx equivalent of |
This should explain what's happening: https://reactjs.org/docs/reconciliation.html#elements-of-different-types In general, defining components inside other components (or Hooks) is a mistake. Instead, usually you want to declare them outside. |
React version: 16.13
Both of the following code snippets produce an input component that loses focus on render:
Sandbox
Sandbox
Context
In an app I'm working on there is a wizard component that does state management for an array of pages. It takes a render prop which is passed the current page and other stuff like status and navigation functions so that the look of the wizard is separated from the state management. As the render props passed to different wizards have gotten more complex, we've had issues with inputs losing focus and even some app crashes.
Preliminary Investigation
In both of the above examples,
ChildComponent
is being remounted on every render of the wizard.One thing I noticed in the 2nd example is that it can be fixed by swapping
Frame
andcreateFrame()
. I find this concerning because I thought functional components were pure functions and when working with pure functions you can swap the left side of an assignment for the right side without affecting the result.Edit:
It seems to be partially a syntax issue. Both examples can be made to work by avoiding JSX
The text was updated successfully, but these errors were encountered: