Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 11, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanflorence/26ea149b36bce6ae75020318471e7a02 to your computer and use it in GitHub Desktop.
Save ryanflorence/26ea149b36bce6ae75020318471e7a02 to your computer and use it in GitHub Desktop.
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