Skip to content

Commit

Permalink
✨ clientsAtom利用atomWithBroadcast同步
Browse files Browse the repository at this point in the history
  • Loading branch information
neila-a committed Jun 14, 2024
1 parent dd94e13 commit 7682244
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/core/src/app/layout/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
"use client";
import atomWithBroadcast from "@verkfi/shared/reader/atomWithBroadcast";
import atomWithInitialValue, {
valueAtomReturn
} from "@verkfi/shared/reader/atomWithInitialValue";
import {
atom
} from "jotai";
emptySymbol
} from "@verkfi/shared/reader/atomWithStorage";
interface clientBase {
id: string;
url: string;
}
export const clientsAtom = atom<clientBase[]>([]);
export const clientsAtom = atomWithInitialValue((valueAtom: valueAtomReturn<clientBase[]>) => atomWithBroadcast(get => {
const got = get(valueAtom);
if (got === emptySymbol) {
return [];
}
return got;
}, (get, set, update: clientBase[]) => set(valueAtom, update), "clients"))[0];

0 comments on commit 7682244

Please sign in to comment.