@pbroom/color-kit/reactColor

createColorStore

Creates a minimal external store holding a ColorState.

functionimport { createColorStore } from '@pbroom/color-kit/react';color-store.ts:50
function createColorStore(  initial: ColorState,): ColorStore;

set compares by reference: passing the current state object does not notify. Listeners run synchronously in subscription order. This is the store useColor and Color use internally; create one yourself to share color state outside React or across roots.

Parameters

initialColorState
The initial state, e.g. from createColorState.

Returns

ColorStoreA store with get, set and subscribe.

Example

TypeScript
import { createColorStore } from '@pbroom/color-kit/react';
import { createColorState } from '@pbroom/color-kit/driver';
import { parse, toHex } from '@pbroom/color-kit';

const store = createColorStore(createColorState(parse('#3b82f6')));
const unsubscribe = store.subscribe(() => console.log('changed'));
store.set(createColorState(parse('#ff6600'))); // logs 'changed'
toHex(store.get().requested); // → '#ff6600'
unsubscribe();

See also