Skip to content

Instantly share code, notes, and snippets.

@brenttimmermans
Last active April 7, 2018 15:37
Show Gist options
  • Save brenttimmermans/8ea780e571b530b81f16bacc1e03dc69 to your computer and use it in GitHub Desktop.
Save brenttimmermans/8ea780e571b530b81f16bacc1e03dc69 to your computer and use it in GitHub Desktop.
Wrapper for passing context to React component with new context API
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