Skip to content
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

Root component updates trigger list remount #59

Closed
pasiba opened this issue Sep 18, 2018 · 3 comments
Closed

Root component updates trigger list remount #59

pasiba opened this issue Sep 18, 2018 · 3 comments
Labels
💬 question Further information is requested

Comments

@pasiba
Copy link

pasiba commented Sep 18, 2018

Is it expected behaviour?

preview

https://codesandbox.io/s/521oq1v574

@bvaughn bvaughn added the 💬 question Further information is requested label Sep 18, 2018
@bvaughn
Copy link
Owner

bvaughn commented Sep 18, 2018

This doesn't look like a "remount" – just a re-render of the <div>s. 😄

Let's use the React profiler to take a look at your sandbox:
sandbox1

The profiler shows us that each time the app re-renders, all of the list items re-render. This is because the list items are inline function components that get recreated each time your app renders:
screen shot 2018-09-18 at 7 36 23 am

This means that React will see them as a new type each time it renders, and so it will re-render them too.

Try moving the list item renders outside of your App render method, like so:
screen shot 2018-09-18 at 7 39 11 am
screen shot 2018-09-18 at 7 41 29 am

Now let's use the profiler to look at this forked sandbox where I did just that:
sandbox-2

The profiler shows us now that only your App component is re-rendering when you call forceUpdate()

Here's the source code for the forked sandbox:
https://codesandbox.io/s/n9z6lr0m2m

Maybe I should update the docs to avoid showing inline render methods. I tried to keep the docs brief so that they could be read easily but I can see how they might be misleading currently.

@bvaughn bvaughn closed this as completed Sep 18, 2018
@bvaughn
Copy link
Owner

bvaughn commented Sep 18, 2018

I have updated the docs to remove inline rendering functions! Hopefully this will avoid confusion in the future. 😅

@pasiba
Copy link
Author

pasiba commented Sep 19, 2018

Thank you for explaining. I really appreciate it 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants