mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-12 13:48:35 +02:00
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome to the frontend as well.  Added a few `biome-ignore` to speed up the process but we may want to check and fix them in the future.
24 lines
673 B
TypeScript
24 lines
673 B
TypeScript
import React from 'react';
|
|
import { createGlobalState } from 'react-hooks-global-state';
|
|
|
|
type UseGlobalState<T> = () => [
|
|
value: T,
|
|
setValue: React.Dispatch<React.SetStateAction<T>>,
|
|
];
|
|
|
|
// Create a hook that stores global state (shared across all hook instances).
|
|
export const createGlobalStateHook = <T>(
|
|
key: string,
|
|
initialValue: T,
|
|
): UseGlobalState<T> => {
|
|
const container = createGlobalState<{ [key: string]: T }>({
|
|
[key]: initialValue,
|
|
});
|
|
|
|
const setGlobalState = (value: React.SetStateAction<T>) => {
|
|
container.setGlobalState(key, value);
|
|
};
|
|
|
|
return () => [container.useGlobalState(key)[0], setGlobalState];
|
|
};
|