Created
November 20, 2018 14:54
-
-
Save joshuacerbito/325b31ee2659e2cc698e234ab010ebe7 to your computer and use it in GitHub Desktop.
Higher Order Component for handling React's Context consumer outside of a component's render function
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"; | |
const WithContext = (Component, Context) => { | |
return props => ( | |
<Context.Consumer> | |
{value => <Component {...props} context={value} />} | |
</Context.Consumer> | |
); | |
}; | |
export default WithContext; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment