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

White list props to check on should component update #25

Open
3den opened this issue Jun 20, 2015 · 0 comments
Open

White list props to check on should component update #25

3den opened this issue Jun 20, 2015 · 0 comments

Comments

@3den
Copy link
Contributor

3den commented Jun 20, 2015

Currently we have a black list props to ignore but that is usually just to avoid unwanted warnings. If you pass down all props of the current component to its children the shouldComponentUpdate returns if any new prop received is different, which will cause the component to render even when it does not care about the prop that was changed.

Using a black list does not scale, it is better to be explicit and white list the props that matter for the current component so that we those are the only ones that can cause the component to re-render or raise warnings.

We can solve that issue on components define propTypes by using the the propTypes as a whitelist of the props that can cause this component to rerender.

Mixing e.g.

 var Component = React.createClass({   
      mixins: [ImmutableMixin],

      // this component only rerenders for changes on the state or on the props defined below
      propTypes: {
          symbol: React.PropTypes.string.isRequired
      },
      ...
 });

I think that same approach can work on with the higher order component.

 var Component = React.createClass({   
      // The higher order immutable component only re renders for changes the propTypes 
      // defined by the wrapped component
      propTypes: {
          symbol: React.PropTypes.string.isRequired
      },
      ...
 });

 exports.module = createImmutableContainer(Component);

cc: @akshayp @dmhood @redonkulus

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

1 participant