Files
outline/app/components/withStores.tsx
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

33 lines
962 B
TypeScript

import hoistNonReactStatics from "hoist-non-react-statics";
import * as React from "react";
import type RootStore from "~/stores/RootStore";
import useStores from "~/hooks/useStores";
type StoreProps = keyof RootStore;
function withStores<
P extends React.ComponentType<ResolvedProps & RootStore>,
ResolvedProps = JSX.LibraryManagedAttributes<
P,
Omit<React.ComponentProps<P>, StoreProps>
>,
>(WrappedComponent: P): React.FC<ResolvedProps> {
const ComponentWithStore = (props: ResolvedProps) => {
const stores = useStores();
return <WrappedComponent {...(props as any)} {...stores} />;
};
ComponentWithStore.displayName = `WithStores(${
WrappedComponent.name || WrappedComponent.displayName
})`;
/**
* https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
*/
hoistNonReactStatics(ComponentWithStore, WrappedComponent);
return ComponentWithStore;
}
export default withStores;