Skip to content

Instantly share code, notes, and snippets.

@wuct
Last active February 19, 2016 03:05
Show Gist options
  • Save wuct/2d86c4824598e2271a09 to your computer and use it in GitHub Desktop.
Save wuct/2d86c4824598e2271a09 to your computer and use it in GitHub Desktop.
Nesting children is also an anti-pure-render pattern.
// Consider <Button /> is a pure render component
import { pure } from 'recompose';
const Button = pure(props =><button>{props.children}</button>);
const App = () => <div>
Call me maybe?
<Button><IconPhone /> Call</Button>
</div>
// Everytime <App /> renders, it creates a new IconPhone (by calling React.createElement(IconPhone)) and pass to <Button />.
// This behavior forces <Button /> to re-render everytime.
// To Avoid this anti-pattern, we should create a new pure render component wrapping <Button />,
// like following:
const WrappedButton = pure(() => <Button><IconPhone /> Call</Button>)
const App = () => <div>
Call me maybe?
<WrappedButton />
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment