Skip to content

Instantly share code, notes, and snippets.

@bultas
Forked from ryanflorence/foo.js
Created May 11, 2018 19:02
Show Gist options
  • Save bultas/429f4a20c56bf78d3d8d6e50eb7a5e62 to your computer and use it in GitHub Desktop.
Save bultas/429f4a20c56bf78d3d8d6e50eb7a5e62 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