2020-07-06 21:59:56 +05:30
|
|
|
import React, { ComponentType } from 'react';
|
2020-05-21 23:38:47 +05:30
|
|
|
import { createMemoryHistory } from 'history';
|
2020-07-06 21:59:56 +05:30
|
|
|
import { DeepPartial } from 'utility-types';
|
|
|
|
|
2020-05-21 23:38:47 +05:30
|
|
|
import storeFactory from 'app/storeFactory';
|
2020-07-22 15:31:12 +05:30
|
|
|
import { State as RootState } from 'app/types';
|
2020-05-21 23:38:47 +05:30
|
|
|
|
|
|
|
import ContextProvider from './ContextProvider';
|
|
|
|
|
2020-07-06 21:59:56 +05:30
|
|
|
type NotOverriddenProps = Omit<React.ComponentProps<typeof ContextProvider>, 'store' | 'history'>;
|
|
|
|
type Props = NotOverriddenProps & {
|
|
|
|
state?: DeepPartial<RootState>;
|
|
|
|
};
|
2020-05-21 23:38:47 +05:30
|
|
|
|
2020-07-06 21:59:56 +05:30
|
|
|
const TestContextProvider: ComponentType<Props> = ({ state = {}, children, ...props }) => {
|
|
|
|
const store = React.useMemo(() => storeFactory(state), []);
|
2020-05-24 04:38:24 +05:30
|
|
|
const history = React.useMemo(createMemoryHistory, []);
|
2020-05-21 23:38:47 +05:30
|
|
|
|
2020-07-06 21:59:56 +05:30
|
|
|
return (
|
|
|
|
<ContextProvider store={store} history={history} {...props}>
|
|
|
|
{children}
|
|
|
|
</ContextProvider>
|
|
|
|
);
|
|
|
|
};
|
2020-05-21 23:38:47 +05:30
|
|
|
|
|
|
|
export default TestContextProvider;
|