Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created October 30, 2018 15:23
Show Gist options
  • Save ajcrites/0afeec47af634e4db38ec80951768c86 to your computer and use it in GitHub Desktop.
Save ajcrites/0afeec47af634e4db38ec80951768c86 to your computer and use it in GitHub Desktop.
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)
}
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