Created
July 31, 2021 02:08
-
-
Save robsonkades/3d2c96cc85e92fa5bf0500d275ee9340 to your computer and use it in GitHub Desktop.
This file contains 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 { AppProps } from 'next/app'; | |
import { RecoilRoot } from 'recoil'; | |
export function withRecoil<T extends AppProps = AppProps>( | |
WrappedComponent: React.ComponentType<T> | |
) { | |
const displayName = | |
WrappedComponent.displayName || WrappedComponent.name || 'Component'; | |
const Component = (props: Omit<T, keyof AppProps>) => { | |
return ( | |
<RecoilRoot> | |
<WrappedComponent {...(props as T)} /> | |
</RecoilRoot> | |
); | |
}; | |
Component.displayName = `withRecoil(${displayName})`; | |
return Component; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment