@cybertools/react
v1.0.1
Published
React state factory (makeProvider), data-fetching hooks and ErrorBoundary for Cyberscope apps.
Readme
@cybertools/react
React state factory (makeProvider), data-fetching hooks and ErrorBoundary for Cyberscope apps.
API
All exports are named, from the single entry @cybertools/react.
| Export | Description |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| makeProvider(options?) | Builds a keyed collection store: Provider, useCollection, useResource, useResourceValue, useCollectionDispatch, useResourceDispatch. |
| makeContext() | Creates the selectable state/dispatch context pair used by makeProvider. |
| createSelectableContext(defaultValue) | Creates a context with listener-based selection (no Consumer). |
| providerSymbol | Marker symbol. |
| useContextSelector(context, selector?) | Subscribes to a selectable context and re-renders only when the selected value changes (deep equality). |
| useFetchPromise(options, deps) | [data, loaded, loading, refresh]. |
| useFetchWithErrorPromise(options, deps) | { data, loaded, loading, error, refresh }. |
| useFetchFnPromise(options, deps) | [func, data, loading, error]; call func(...args) to run the action. |
| ErrorBoundary | Class component rendering fallback (or nothing) after a child throws. |
import { makeProvider } from "@cybertools/react";
const audits = makeProvider<{ name: string }>({
getResourceInitialState: () => ({ name: "" }),
});
// <audits.Provider value={{ a: { name: "x" } }}>...</audits.Provider>
const name = audits.useResource("a", (r) => r.name);React support
Peer range react@^18.2.0 || ^19.0.0. makeProvider relies on render-phase setState and scheduler priorities; it is a verbatim, typed port of the legacy implementation. CI tests run on React 19.
Optional @sentry/react
useFetchFnPromise({ sentry: true }) dynamically imports @sentry/react and calls captureException on failure. @sentry/react is an optional peer dependency; install it only if you use sentry: true.
