Created
September 14, 2016 01:37
-
-
Save developit/d3bd1b51f50a82ec4e6cd4d8678264f0 to your computer and use it in GitHub Desktop.
HoC stuff
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
| // 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