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

New Rule: Do not allow generation of new objects in props #89

Closed
benbayard opened this issue Apr 18, 2017 · 3 comments
Closed

New Rule: Do not allow generation of new objects in props #89

benbayard opened this issue Apr 18, 2017 · 3 comments

Comments

@benbayard
Copy link

benbayard commented Apr 18, 2017

Similar to jsx-no-lambda, if in a prop you do:

<MyComponent 
  style={{display: 'block'}}
/>

this will force any pure component to re-render every time.

Ideally, we could check in render to see if any new objects are generated there. Such as:

render() {
  const style = {display: 'block'};

  return <MyComponent 
    style={style}
  />
}

but that could be a separate rule.

@IllusionMH
Copy link
Contributor

Had similar thought during jsx-no-lambda rewrite.

More ideal case described above - move style variable outside of component. 😃

Also I'd like to suggest further improvements for both rule proposed in this issue as well as for jsx-no-lambda:

  • For this rule - also track array literals passed directly to attributes.
  • For both - track for default (or fallback) values directly in jsx attributes (e.g. <List items={props.items || []} />)

See React.js pure render performance anti-pattern for the reference.

@benbayard
Copy link
Author

Another thing to consider would be:

<MyComponent myProp={condition ? realValue : {}} />

@adidahiya
Copy link
Contributor

Closing due to deprecation timeline, see #210

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

No branches or pull requests

3 participants