mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-02 14:02:37 +00:00
* 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>
27 lines
774 B
TypeScript
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 };
|
|
};
|