Skip to content

Instantly share code, notes, and snippets.

@ruanlinos
Created June 27, 2022 21:34
Show Gist options
  • Save ruanlinos/c20b363802b455315bc1d597f6c8ce56 to your computer and use it in GitHub Desktop.
Save ruanlinos/c20b363802b455315bc1d597f6c8ce56 to your computer and use it in GitHub Desktop.
import React, { ReactElement } from 'react';
import { Provider } from 'react-redux';
import { persistor, store } from '../store';
import { PersistGate } from 'redux-persist/integration/react';
import { Persistor } from 'redux-persist';
export default function withProvider<T>(
WrapperComponent: React.FC<T>,
enhancedStore: any = store
): (props: T) => ReactElement {
const Gate = (PersistGate as unknown) as React.FC<{ persistor: Persistor }>;
return props => (
<Provider store={enhancedStore}>
<Gate persistor={persistor}>
<WrapperComponent {...props} />
</Gate>
</Provider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment