mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-21 08:59:07 +01:00
Better multi-window updates
This commit is contained in:
14
src-web/hooks/useRequestUpdateKey.ts
Normal file
14
src-web/hooks/useRequestUpdateKey.ts
Normal 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() }));
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user