-
-
Save evenchange4/754b48ccf8fd90033930 to your computer and use it in GitHub Desktop.
Nesting children is also an anti-pure-render pattern.
This file contains hidden or 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 | |
const AntiPureComponet = () => <div> | |
Call me maybe? | |
<Button><IconPhone /> Call</Button> | |
</div> | |
// When <AntiPureComponet /> renders, it creates a new child (by calling React.createElement) 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: | |
import { pure } from 'recompose'; | |
const WrappedButton = pure(() => <Button><IconPhone /> Call</Button>) | |
const PureComponet = () => <div> | |
Call me maybe? | |
<WrappedButton /> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment