Created
May 11, 2018 18:46
-
-
Save ryanflorence/26ea149b36bce6ae75020318471e7a02 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