Skip to content

Instantly share code, notes, and snippets.

@developit
Created September 14, 2016 01:37
Show Gist options
  • Select an option

  • Save developit/d3bd1b51f50a82ec4e6cd4d8678264f0 to your computer and use it in GitHub Desktop.

Select an option

Save developit/d3bd1b51f50a82ec4e6cd4d8678264f0 to your computer and use it in GitHub Desktop.
HoC stuff
// HoC
// localize({ a:'b' })(MyFoo)
const localize = dict => Child => class Connected extends Component {
getChildContext() {
return { dict }
}
render(props) {
return <Child {...props} />
}
}
// Not HoC :(
// <Localize dict={{ a:'b' }}><MyFoo /></Localize>
// const MyFoo = <Localize dict={{ a:'b' }}><MyActualFoo /></Localize>
class Localize extends Component {
getChildContext() {
return { dict }
}
render() {
return this.props.children[0]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment