type ContextProps<T = object> = {
store: T,
updateStore: React.Dispatch<T>
};
export default React.createContext<Partial<ContextProps>>({}); // is there any way to pass the generic? so store can correct type
export function Provider<T, K>(props: T & { store: K }) {
const [globalState, updateStore] = React.useState(props.store);
const value = React.useMemo(
() => ({
store: globalState,
updateStore,
}),
[globalState],
);
return <StateMachineContext.Provider value={value} {...props} />;
}
Is there any way to pass generic into Context, so value can have the correct type?