Last active
April 7, 2018 15:37
-
-
Save brenttimmermans/8ea780e571b530b81f16bacc1e03dc69 to your computer and use it in GitHub Desktop.
Wrapper for passing context to React component with new context API
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
import React from 'react'; | |
export default function withContext(Context) { | |
return (Component) => (props) => ( | |
<Context.Consumer> | |
{ context => <Component {...props} context={context} /> } | |
</Context.Consumer> | |
); | |
} | |
/* | |
* Example: | |
* export default withContext(MyContext)(SomeCoolComponent) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment