Appearance
@shtse8/fluxus / src / stateProvider
Function: stateProvider()
stateProvider<
T>(initialValue,options?):StateProviderInstance<T>
Defined in: src/providers/stateProvider.ts:113
Creates a StateProviderInstance which manages a mutable piece of state.
Type Parameters
T
T
The type of the state value.
Parameters
initialValue
The initial value for the state, or a function that computes the initial value using a ScopeReader. If a function is provided, it will be called once per scope when the provider is first initialized within that scope.
T | (reader) => T
options?
ProviderOptions
Returns
The created StateProvider instance.
Example
ts
// Simple counter state provider
const counterProvider = stateProvider(0);
// State provider with initial value computed from another provider
const userProvider = stateProvider<{ name: string; id: number } | null>(null);
const userIdProvider = stateProvider((reader) => reader.read(userProvider)?.id ?? -1);