Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Questions for onlyUpdateForPropTypes #548

Open
evisong opened this issue Oct 27, 2017 · 1 comment
Open

Questions for onlyUpdateForPropTypes #548

evisong opened this issue Oct 27, 2017 · 1 comment

Comments

@evisong
Copy link

evisong commented Oct 27, 2017

Hi, team,

First of all, many thanks for this great lib, we use it a lot together with stateless function components in our production code.

We use pure and onlyUpdateForKeys API to improve render performance, btw, our use case for onlyUpdateForKeys is mainly to exclude those PropTypes.func props. And we find there is also a onlyUpdateForPropTypes. We've some questions on it.

According to https://reactjs.org/docs/typechecking-with-proptypes.html, PropTypes is a built-in typechecking abilities of React. So the purpose of PropTypes is validation but not optimization. When using onlyUpdateForPropTypes, we'll have to avoid to set PropTypes for a component's props that we don't wish it to trigger re-render, ultimately, if we set PropTypes for all props (for validation purpose), onlyUpdateForPropTypes won't help the performance improvement. This seems tricky for me.

So my questions will be:

  • Is it by design that onlyUpdateForPropTypes are tightly bound to PropTypes?
  • Is it possible to add an optional argument to onlyUpdateForPropTypes, e.g. onlyUpdateForPropTypes([PropTypes.number, PropTypes.string, PropTypes.object]), so that it will be more flexible?

Thanks.

@istarkov
Copy link
Contributor

Based on my experience all that optimisations except pure is very error prone. Its sometimes not easy to get why additional props you add to existing components not updated in UI. Having few accidents we decided to not use such optimisations at all. Based on this I dont like the idea to make onlyUpdateFor* hocs more usable or general, as IMO the only good usecase to use them is some very low level controls

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

2 participants