Created
October 30, 2018 15:23
-
-
Save ajcrites/0afeec47af634e4db38ec80951768c86 to your computer and use it in GitHub Desktop.
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
function withToggle(Component) { | |
function Wrapper(props, ref) { | |
return ( | |
<Toggle.Consumer> | |
{toggleContext => ( | |
<Component toggle={toggleContext} {...props} ref={ref} /> | |
)} | |
</Toggle.Consumer> | |
) | |
} | |
Wrapper.displayName = `withToggle(${Component.displayName || | |
Component.name})` | |
return hoistNonReactStatics(React.forwardRef(Wrapper), Component) | |
} |
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
function withToggle(Component) { | |
function Wrapper(props, ref) { | |
const toggleContext = useContext(ToggleContext); | |
return <Component toggle={toggleContext} {...props} ref={ref} /> | |
} | |
Wrapper.displayName = `withToggle(${Component.displayName || | |
Component.name})` | |
return hoistNonReactStatics(React.forwardRef(Wrapper), Component) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment