This repository has been archived on 2025-05-09. You can view files and clone it, but cannot push or open issues or pull requests.
EvoCalculator/src/client/hocs/withStore.tsx
Владислав Чикалкин 4745d0cfd6 front: partial
2020-08-26 14:56:23 +03:00

25 lines
772 B
TypeScript

import React, { ComponentType } from "react";
// import hoistNonReactStatics from "hoist-non-react-statics";
import { useStores } from "../hooks/useStores";
export type TWithStoreHOC = <P extends unknown>(
Component: ComponentType<P>
) => (props: P) => JSX.Element;
export const withStore: TWithStoreHOC = (WrappedComponent) => (props) => {
const ComponentWithStore = () => {
const store = useStores();
return <WrappedComponent {...props} store={store} />;
};
ComponentWithStore.defaultProps = { ...WrappedComponent.defaultProps };
ComponentWithStore.displayName = `WithStores(${
WrappedComponent.name || WrappedComponent.displayName
})`;
// hoistNonReactStatics(ComponentWithStore, WrappedComponent);
return <ComponentWithStore />;
};