Skip to content

CreateChimericSyncFactory

Provided by @chimeric/react.

Creates a reusable factory bound to a state management library (Redux, Zustand, etc.) via an adapter. This is the recommended way to create ChimericSync instances.

import { CreateChimericSyncFactory } from '@chimeric/react';
import { create } from 'zustand';
const useTodoStore = create<TodoStore>((set) => ({ ... }));
const ChimericSyncFactory = CreateChimericSyncFactory<TodoStore>({
getState: () => useTodoStore.getState(),
useSelector: useTodoStore,
});
// Create sync operations from the factory
const getTodoById = ChimericSyncFactory({
selector: (params: { id: string }) => (state) => state.dict[params.id],
reducer: (record) => (record ? toDomain(record) : undefined),
});
import { useAppSelector } from './hooks';
import { appStore } from './store';
const ChimericSyncFactory = CreateChimericSyncFactory({
getState: () => appStore.getState(),
useSelector: useAppSelector,
});
const getActiveCount = ChimericSyncFactory({
selector: () => (state) => state.todos.filter((t) => !t.completed).length,
});
PropertyTypeDescription
getState() => TStateSynchronous state accessor
useSelector<T>(selector: (state: TState) => T) => TReact hook for subscribing to state
PropertyTypeDescription
selector(params) => (state) => TSelectedSelector factory — takes params, returns a state selector
reducer(selected, params) => TResultOptional. Transform the selected value before returning.
// Idiomatic — reads directly from the store
const todo = getTodoById({ id: '123' });
// Reactive — subscribes to store updates via the hook
const todo = getTodoById.useHook({ id: '123' });

See the RTK SPA example and Next.js example for real-world usage.