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

React not bails out in the case props not changed #149

Closed
mh-alahdadian opened this issue Feb 21, 2020 · 4 comments
Closed

React not bails out in the case props not changed #149

mh-alahdadian opened this issue Feb 21, 2020 · 4 comments

Comments

@mh-alahdadian
Copy link

The funny thing is that React already does this, except a level shallower than memo. React already bails out by default if oldProps === newProps. I.e. if the props object itself is the same. This is ofc much less common to match but it's also significantly cheaper to do.

Originally posted by @sebmarkbage in #108 (comment)

Thanks for that you mentioned this point but why this sandbox not work as like you said? I checked the props in child element and they are not equal to props I send to React.createElement ! why ?

And at the last please tell us where can we find all of these rules and points to better understand what is going on behind react

@illuminist
Copy link

Because newProps.children !== oldProps.children.

Wrapping Child with React.memo will make sure that child element will stay the same as previous props given same props for the Child.

@mh-alahdadian
Copy link
Author

Because newProps.children !== oldProps.children.

Wrapping Child with React.memo will make sure that child element will stay the same as previous props given same props for the Child.

the above example doesn't have any children props and I think props.children == undefined and is equal between multiple renders

@illuminist
Copy link

There are the children of React.Fragment(<>{children}</>).

@eddiecooro
Copy link

@mha15 I thinks that's because React creates a new prop object every time the React.createElement gets called. You can check that for yourself here
But I still don't quite understand where the oldProps === newProps check that @sebmarkbage has talked about would be useful. (maybe some internal code paths where an already existing fiber gets re-rendered?)

@gaearon gaearon closed this as completed Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants