@zag-js/svelte
Version:
The svelte wrapper for zag
12 lines (11 loc) • 428 B
JavaScript
export function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
let snapshot = $state(getServerSnapshot !== undefined && typeof window === "undefined" ? getServerSnapshot() : getSnapshot());
$effect(() => {
snapshot = getSnapshot();
const unsubscribe = subscribe(() => {
snapshot = getSnapshot();
});
return unsubscribe;
});
return () => snapshot;
}