mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
global mutate hook
This commit is contained in:
parent
cce66e8d9b
commit
0bd70e7695
16
web/src/hooks/use-global-mutate.ts
Normal file
16
web/src/hooks/use-global-mutate.ts
Normal file
@ -0,0 +1,16 @@
|
||||
// https://github.com/vercel/swr/issues/1670#issuecomment-1844114401
|
||||
import { useCallback } from "react";
|
||||
import { cache, mutate } from "swr/_internal";
|
||||
|
||||
const useGlobalMutation = () => {
|
||||
return useCallback((swrKey: string | ((key: string) => boolean), ...args) => {
|
||||
if (typeof swrKey === "function") {
|
||||
const keys = Array.from(cache.keys()).filter(swrKey);
|
||||
keys.forEach((key) => mutate(key, ...args));
|
||||
} else {
|
||||
mutate(swrKey, ...args);
|
||||
}
|
||||
}, []) as typeof mutate;
|
||||
};
|
||||
|
||||
export default useGlobalMutation;
|
||||
Loading…
Reference in New Issue
Block a user