Files
wanderer/assets/js/hooks/Mapper/utils/abstractContextProvider.tsx
Dmitry Popov cb41a33546 Custom signatures (#37)
* feat(signatures): Add custom info to system signatures

* feat(connections): Add custom info to system connections

* feat(Map): Add system signature type

* feat(Map): Update wormhole types info

* feat(Map): Add undo action for removed systems

* feat(Map): Delete systems on Backspace hotkey

* feat(Map): Update k-space systems background & styles

* feat(Map): Update systems status background styles

* feat(Map): add support for new wh type data. add signatures settings modal menu; reworked signatures widget - was added info of wormhole;

---------

Co-authored-by: achichenkov <aleksei.chichenkov@telleqt.ai>
2024-10-24 13:10:17 +04:00

27 lines
774 B
TypeScript

import { createContext, ReactNode, useContext, useState } from 'react';
type ContextType<T> = {
value: T;
setValue: (newValue: T) => void;
};
export const createGenericContext = <T,>() => {
const context = createContext<ContextType<T> | undefined>(undefined);
const Provider = ({ children, initialValue }: { children: ReactNode; initialValue: T }) => {
const [value, setValue] = useState<T>(initialValue);
return <context.Provider value={{ value, setValue }}>{children}</context.Provider>;
};
const useContextValue = () => {
const contextValue = useContext(context);
if (!contextValue) {
throw new Error('useContextValue must be used within a Provider');
}
return contextValue;
};
return { Provider, useContextValue };
};