Skip to content

Instantly share code, notes, and snippets.

@robsonkades
Created July 31, 2021 02:08
Show Gist options
  • Save robsonkades/3d2c96cc85e92fa5bf0500d275ee9340 to your computer and use it in GitHub Desktop.
Save robsonkades/3d2c96cc85e92fa5bf0500d275ee9340 to your computer and use it in GitHub Desktop.
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