Skip to content

@xtandard/lib/react

React hooks and components: useStream/StreamRenderer, Providers, useDynamicRefs, usePreventAutoFocus (peers react, @tanstack/react-query).

import { … } from "@xtandard/lib/react";
Name Summary
provider Create a typed ProviderSpec tuple with prop inference and required-prop enforcement.
Providers Compose multiple React providers without deeply nesting JSX. Eliminates “provider hell” by flattening the tree into an array.
StreamRenderer Renders different content based on stream state using TanStack Query.
useDynamicRefs React hook that returns a ref “getter” function. Call the getter with a string key to get (or create) a RefObject for that key. Useful for dynamic lists, tabs, or any UI where the number of refs isn’t known at compile time.
usePreventAutoFocus Hook that prevents auto-focus behavior while still maintaining focus management. Useful for modal dialogs (e.g. Radix Dialog) where you want to control the initial focus.
useStream Hook for consuming streams using TanStack Query’s streamedQuery.
Name Summary
DynamicRefGetter Returns a ref for the given key, creating one if it doesn’t exist yet. Overloads ensure that calling without a key returns undefined.
UseDynamicRefsOptions Options for useDynamicRefs.
Name Summary
AnyProps Loose props record accepted by a provider component (Record<string, unknown>).
ChildrenData Children render prop data - includes status and all relevant data
DelayConfig Granular delay configuration
ErrorData Error data passed to error render prop
OnErrorData Data passed to onError callback
OnItemData Data passed to onItem callback
OnSuccessData Data passed to onSuccess callback
ProviderArgProps
ProviderInputProps
ProviderPropsArg Rest-args tuple of provider(Component, ...args): the props argument, required only when TProps has required keys besides children.
ProviderSpec A provider entry for Providers.
ProvidersProps Props for the Providers component.
RefMap The internal Map type for a given ref element type.
RenderProp Render prop: can be ReactNode or function returning ReactNode
RenderPropNoData Render prop without data (for loading)
RequiredKeys
RetryData Data passed to retry callback
StreamingData Streaming data passed to streaming render prop
StreamMode Accumulation mode for stream items. - "accumulate" (default): keep all items in memory - "latest": only keep the most recent item
StreamReducer Custom reducer for stream state. Receives current state and new item, returns new state.
StreamRendererBaseProps Base props for StreamRenderer
StreamRendererProps Props for StreamRenderer - supports all accumulation modes
StreamSourceWithReturn A generator or AsyncChannel whose return value is typed as TReturn.
StreamState Stream state with accumulated items
SuccessData Success data passed to success render prop
UseStreamAccumulateOptions Options with default accumulation (all items)
UseStreamBaseOptions Base options shared by all useStream configurations
UseStreamLatestOptions Options with “latest” mode (only keep last item)
UseStreamMaxItemsOptions Options with maxItems (sliding window)
UseStreamOptions Props for useStream hook - mutually exclusive accumulation options
UseStreamReducerOptions Options with custom reducer
UseStreamReducerResult Result type for useStream with custom reducer
UseStreamResult Result type for standard useStream (accumulate, latest, maxItems modes)
UseStreamSource Any StreamSource, spelled so that a generator’s (or channel’s) return type is inferred as TReturn: useStream({ source: gen }) types returnValue without explicit type arguments.