createGlobalState#

Wrap a state factory so its first call runs inside a detached effectScope() and every later call returns the same cached result — app-wide shared signals without a store. Cross-platform — import from @sigx/use.

TypeScript
import { signal } from 'sigx';
import { createGlobalState } from '@sigx/use';

export const useFilters = createGlobalState(() =>
    signal({ q: '', tags: [] as string[] })
);

// any component gets the SAME signal:
const filters = useFilters();
filters.q = 'sigx';

The scope the factory runs in is never disposed — the state lives for the process. That's the point: it's a lightweight singleton for device- and UI-level state that every component shares.

SSR caveat. The cache is module-level, shared across every request in the process. Use it for device/UI state only, never per-user data — that's defineStore's job. A per-user value cached here would leak between requests.

Signature#

TypeScript
function createGlobalState<Fn extends (...args: never[]) => unknown>(stateFactory: Fn): Fn;

The returned function has the same signature as the factory you pass — the wrapping is transparent to callers.

Platform: everywhere.

See also#

  • createSharedComposable — refcounted sharing that tears down when the last subscriber leaves, for effect-ful composables.
  • @sigx/storedefineStore for structured, per-user application state.
  • Conventions — the shared input/output patterns.