Last active
February 19, 2016 03:05
-
-
Save wuct/2d86c4824598e2271a09 to your computer and use it in GitHub Desktop.
Nesting children is also an anti-pure-render pattern.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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