Recompose: pure is useless for components with children

Created on 13 Mar 2018  路  5Comments  路  Source: acdlite/recompose

as far as i understand, the "children" prop is always re-created and receives a new reference.

using the "pure" hoc on components with children is almost like writing shallowEqual(...) || true meaning we pay the price of shallowEqual but still always re-render.

so i suggest doing one of the two:

Most helpful comment

was a little lazy to do it but here is a sandbox.
don't you think in this case the component should not re-render?

https://codesandbox.io/s/w2k4vlp1j5

i think people who make their components "pure" should at least be warned in the readme about this behaviour

All 5 comments

may you just try before writing ;-) It is a good exercise why it works as expected. Ill close this as you are not right

btw seems I got you, what if children passed from the top component, component must be rerendered its expected behaviour

If you need behaviour from that lib please use that lib

was a little lazy to do it but here is a sandbox.
don't you think in this case the component should not re-render?

https://codesandbox.io/s/w2k4vlp1j5

i think people who make their components "pure" should at least be warned in the readme about this behaviour

The behavior of pure is same as React.PureComponent, so I think there is no need to add a warning. By the way, you might want to have a look at this babel plugin.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeron-diovis picture jeron-diovis  路  4Comments

jethrolarson picture jethrolarson  路  4Comments

isubasti picture isubasti  路  3Comments

joncursi picture joncursi  路  3Comments

robbporto picture robbporto  路  3Comments