mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
94ecaa80a8
* refactor: rename createPersistentGlobalStateHook helper * refactor: move features filter state out of localStorage * refactor: show search state in page title * refactor: remove unused import * refactor: add a state chip to SearchField * refactor: improve var names
24 lines
671 B
TypeScript
24 lines
671 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];
|
|
};
|