"use client";
import * as React from "react";
import { getWidgetSharedState } from "./WidgetSharedState.js";
function useWidgetSharedState(key, namespace = "global") {
  const store = React.useMemo(() => getWidgetSharedState(namespace), [namespace]);
  const subscribe = React.useCallback(
    (onStoreChange) => {
      const unsubscribe = store.subscribe(key, () => onStoreChange());
      return unsubscribe;
    },
    [key, store]
  );
  const getSnapshot = React.useCallback(() => store.get(key), [key, store]);
  const value = React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
  const setValue = React.useCallback(
    (nextValue) => {
      store.set(key, nextValue);
    },
    [key, store]
  );
  return [value, setValue];
}
export {
  useWidgetSharedState
};
//# sourceMappingURL=useWidgetSharedState.js.map
