import { useSyncExternalStore } from 'react'; /** * The score the open panel computes as the post is edited, for the toolbar * button: the stored score only changes when the post is saved. */ let current: number | null = null; const listeners = new Set<() => void>(); export const setLiveScore = (score: number | null): void => { if (score === current) { return; } current = score; listeners.forEach(listener => listener()); }; export const getLiveScore = (): number | null => current; const subscribe = (listener: () => void): (() => void) => { listeners.add(listener); return () => listeners.delete(listener); }; export const useLiveScore = (): number | null => useSyncExternalStore(subscribe, () => current);