-
-
Save bultas/429f4a20c56bf78d3d8d6e50eb7a5e62 to your computer and use it in GitHub Desktop.
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
class Optimized extends React.PureComponent { | |
render() { | |
return this.props.children | |
} | |
} | |
const SomeConsumer = ({ slice, children } => ( | |
<ActualConsumer> | |
{(state) => ( | |
<Optimized slice={state[slice]}> | |
{children(state[slice])} | |
</Optimized> | |
)} | |
</ActualConsumer> | |
)) | |
<SomeConsumer slice="user"> | |
{user => ( | |
// only gets updated user when it needs to | |
)} | |
</SomeConsumer> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment