mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 21:53:36 +01:00
17 lines
548 B
TypeScript
17 lines
548 B
TypeScript
import { atom, useAtomValue } from 'jotai';
|
|
import { generateId } from '../lib/generateId';
|
|
import { jotaiStore } from '../lib/jotai';
|
|
|
|
const keyAtom = atom<Record<string, string>>({});
|
|
|
|
export function useRequestUpdateKey(requestId: string | null) {
|
|
const keys = useAtomValue(keyAtom);
|
|
const key = keys[requestId ?? 'n/a'];
|
|
return {
|
|
updateKey: `${requestId}::${key ?? 'default'}`,
|
|
wasUpdatedExternally: (changedRequestId: string) => {
|
|
jotaiStore.set(keyAtom, (m) => ({ ...m, [changedRequestId]: generateId() }));
|
|
},
|
|
};
|
|
}
|