Skip to main content

Core without React

The hooks are a thin React skin over an engine that doesn't know React exists. This section documents that engine — everything you can call from a worker, a plain module, a test, or another framework.

You already have it. use-everywhere re-exports the whole of @use-everywhere/core, so there is one dependency either way:

import { createSharedStore, newer, MemoryHub } from 'use-everywhere';
// identical to:
import { createSharedStore, newer, MemoryHub } from '@use-everywhere/core';

Install @use-everywhere/core directly only if you have no React at all.

What lives where

HooksuseSharedState, useLeader, …Hooks
FactoriesdefineChannel, defineStoreHooks — they return hooks, so they're documented alongside them
EnginescreateSharedStore, createChannel, createPresence, createLeaderEngines
Version clocknewer, VersionThe version clock
TransportsMemoryHub, NoopTransport, BroadcastChannelTransportTransports
Debug seamobserveBus, enableDebug, getBusNamesDebugging
Escape hatchesgetSharedStore, getLeader, DEFAULT_NAME, the error classesEscape hatches
Cross-origin windowsopenWindow, connectToOpeneruseOpenedWindow
Persistence adapterslocalStorageAdapter, webStorageAdapterdefineStore

Every signature is also generated from the source in the API reference. This section is the prose; that one is the exhaustive list.

The one rule

An engine is a resource, not a value. It holds a bus, a heartbeat, and listeners, so whatever you create, you close:

const store = createSharedStore('settings', { theme: 'dark' });
// …later
store.close();

The React hooks handle this for you — they memoise one engine per name for the lifetime of the page, which is why there's no Provider and no cleanup to write. Outside React, it's yours.

Engines sharing a name share a bus, and therefore share one clientId and one underlying BroadcastChannel:

const store = createSharedStore('app', {});
const presence = createPresence('app');

store.clientId === presence.clientId; // true — same tab, same identity

That's why presence works even in a tab that never created a Presence: the heartbeat lives on the bus, not on the engine.