Better multi-window updates

This commit is contained in:
Gregory Schier
2023-03-29 21:53:20 -07:00
parent bc40e22008
commit dab2df7e79
16 changed files with 180 additions and 136 deletions

View File

@@ -0,0 +1,14 @@
import { createGlobalState } from 'react-use';
import { generateId } from '../lib/generateId';
const useGlobalState = createGlobalState<Record<string, string>>({});
export function useRequestUpdateKey(requestId: string | null) {
const [keys, setKeys] = useGlobalState();
return {
updateKey: `${requestId}::${keys[requestId ?? 'n/a']}`,
wasUpdatedExternally: (changedRequestId: string) => {
setKeys((m) => ({ ...m, [changedRequestId]: generateId() }));
},
};
}