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
Why do PureComponents need props? #2186
Comments
For a quick test yourself, use this code:
|
Does the rule warn on Child2? |
Yes. |
With ignorePureComponents true, it’s not ignoring them, so that seems like a bug. |
It was intended, so you could say it's not a bug, but it enforces something that's not ideal. |
oh. good point. I’d expect react not to rerender a component that gets no props or context, but it might not have chosen to apply that optimization. |
Perhaps on the off chance that it could depend on some global state? |
If it does, react explicitly doesn't guarantee a rerender - only props and state do that. |
Hopefully I understood you correctly. Please checkout: #2238. |
Fixed by #2238. |
I'm using
"react/prefer-stateless-function": [1, { "ignorePureComponents": true }]
When I have a PureComponent that doesn't have props, it shows a warning.
However, the component below WILL re-render if the render() of its parent is called
You can see it with the React devtool in Chrome, turn on "highlight update"
If I change it to a PureComponent, it does not re-render:
So to me, a PureComponent without props makes perfect sense.
The text was updated successfully, but these errors were encountered: