Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

Add a recommendation to use .shouldComponentUpdate or React.PureComponent in the console.log #35

Open
ManasJayanth opened this issue Apr 20, 2017 · 5 comments

Comments

@ManasJayanth
Copy link

ManasJayanth commented Apr 20, 2017

As opposed to just showing that props are unchanged.

@ManasJayanth ManasJayanth changed the title Add a recommendation to use .shouldComponentUpdate or React.PureComponent Add a recommendation to use .shouldComponentUpdate or React.PureComponent in the console.log Apr 20, 2017
@caesarsol
Copy link

I wouldn't, because there are many better ways to prevent wasted renders, especially if using Redux or Mobx. And there could be new methods in the future.

@ManasJayanth
Copy link
Author

Better ways? Can you elaborate?

@bf
Copy link

bf commented Apr 21, 2017

Yes please elaborate. The readme should at least point to some resources and showcase different the approaches.

@saitonakamura
Copy link

I think the point of @caesarsol is that avoiding re-render is not only about PureComponent and implementing shoudComponentUpdate by hand, but a much more wider topic. For example, if you're using connect from react-redux to pass state parts to props, it has pure option which is true by default and does the same thing as PureComponent. Or if you're using stateless component, you can't implement shouldComponentUpdate, but instead of converting to PureComponent you can use pure function from recompose
So advocating using PureComponent or shouldComponentUpdate looks slighly opinionated

@caesarsol
Copy link

Sorry for the delay.

That's exactly my point!

For example the recommended way to better performance in my opinion is to divide in multiple connected components, which render independently.

But it's not an absolite rule because too many connected components can actually slow down the page...

The important thing is that shouldComponentUpdate is mostly discouraged, because is a step back to imperative programming while React tends to be declarative.

Redux has connect which already optimizes renders, if you use it correctly.

I'm sure @gaearon could give many more advices, and already has somewhere between Medium and Twitter :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants