
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-state-forge
Advanced tools
A lightweight and modular state management library for React applications, designed to handle various state scenarios such as **basic**, **asynchronous**, **loadable**, and **controllable** states. With support for **nested states** and seamless integrati
A lightweight and modular state management library for React applications, designed to handle various state scenarios such as basic, asynchronous, loadable, and controllable states. With support for nested states and seamless integration with React Suspense, this library ensures efficient state management by minimizing unnecessary rerenders.
This library covers a broad range of state needs, from simple value storage to asynchronous data management and polling-based controls:
Whether you need simple state handling, asynchronous logic, or precise control over complex loading flows, this library provides the flexibility to fit your needs.
using npm:
npm install --save react-state-forge
or yarn:
yarn add react-state-forge
or pnpm:
pnpm add react-state-forge
| State | AsyncState | LoadableState | ControllableLoadableState | |
|---|---|---|---|---|
| getValue | ✅ | ✅ | ✅ | ✅ |
| setValue | ✅ | ✅ | ✅ | ✅ |
| onValueChange | ✅ | ✅ | ✅ | ✅ |
| useValue / Controller | ✅ | ✅ | ✅ | ✅ |
| useMappedValue / MappedController | ✅ | ✅ | ✅ | ✅ |
| useMergedValue / MergedController | ✅ | ✅ | ✅ | ✅ |
| use / SuspenseController | ❌ | ✅ | ✅ | ✅ |
| useAll / SuspenseAllController | ❌ | ✅ | ✅ | ✅ |
| getPromise | ❌ | ✅ | ✅ | ✅ |
| onSlowLoading | ❌ | ✅ | ✅ | ✅ |
| awaitOnly / SuspenseOnlyController / SuspenseOnlyAllController | ❌ | ✅ | ✅ | ✅ |
| .error | ❌ | ✅ | ✅ | ✅ |
| .isLoaded | ❌ | ✅ | ✅ | ✅ |
| .load | ❌ | ❌ | ✅ | ✅ |
| withoutLoading | ❌ | ❌ | ✅ | ✅ |
| .loading.pause | ❌ | ❌ | ❌ | ✅ |
| .loading.resume | ❌ | ❌ | ❌ | ✅ |
| .loading.reset | ❌ | ❌ | ❌ | ✅ |
createState<T>(): State<T | undefined>;
createState<T>(initialValue: T): State<T>;
createState<T>(getInitialValue: () => T): State<T>;
Creates a basic state with an initial value.
import createState from 'react-state-forge/createState';
import useValue from 'react-state-forge/useValue';
import setValue from 'react-state-forge/setValue';
const togglerState = createState(false);
const Togglers = () => (
<div>
<button
onClick={() => {
setValue(togglerState, true);
}}
>
turn on
</button>
<button
onClick={() => {
setValue(togglerState, false);
}}
>
turn off
</button>
<button
onClick={() => {
setValue(togglerState, (prevValue) => !prevValue);
}}
>
switch
</button>
</div>
);
const Light = () => {
const value = useValue(togglerState);
return <div>light {value ? 'on' : 'off'}</div>;
};
const Component = () => (
<div>
<div>
<Light />
</div>
<div>
<Togglers />
</div>
</div>
);
createNestedState<T>(): NestedState<T | undefined>;
createNestedState<T>(initialValue: T): NestedState<T>;
createNestedState<T>(getInitialValue: () => T): NestedState<T>;
Creates a nested state, where individual parts behave independently, triggering updates only when specific parts change. It allows for more efficient reactivity in complex data structures by minimizing unnecessary rerenders.
import createNestedState from 'react-state-forge/createNestedState';
import useValue from 'react-state-forge/useValue';
import setValue from 'react-state-forge/setValue';
const userState = createNestedState({
profile: { name: 'Alice', age: 25 },
});
const Name = () => {
const nameState = userState.scope().profile.name.end$;
const name = useValue(nameState);
return (
<input
value={name}
onChange={(e) => {
setValue(nameState, e.target.value);
}}
/>
);
};
const Age = () => {
const ageState = userState.scope().profile.age.end$;
const age = useValue(ageState);
return (
<input
value={age}
type='number'
onChange={(e) => {
setValue(ageState, +e.target.value);
}}
/>
);
};
const Component = () => (
<div>
<div>
<Name />
</div>
<div>
<Age />
</div>
</div>
);
Creates a state with varying levels of capabilities based on the provided options:
createAsyncState<T, E = any>(
options?: AsyncStateOptions<T>
): AsyncState<T, E>;
type AsyncStateOptions<T> = {
value?: T | (() => T);
isLoaded?(value: T, prevValue: T | undefined, attempt: number): boolean;
};
represents a state that supports asynchronous operations. It extends a regular state by introducing the following additional internal states:
createAsyncState<T, E = any>(
options: LoadableStateOptions<T, E>
): LoadableState<T, E>;
type LoadableStateOptions<T, E = any> = AsyncStateOptions<T> & {
load(this: AsyncState<T, E>): void | (() => void);
loadingTimeout?: number;
reloadIfStale?: number;
reloadOnFocus?: number;
};
Extends AsyncState with additional loading functionality, allowing the state to be loaded or reloaded.
Extends LoadableState with additional control over the loading process, including pause, resume, and reset.
createAsyncState<T, E = any>(
options: ControllableLoadableStateOptions<T, E>
): ControllableLoadableState<T, E>;
type ControllableLoadableStateOptions<T, E = any> = LoadableStateOptions<
T,
E
> & {
pause(): void;
resume(): void;
reset(): void;
};
MIT © Krombik
FAQs
A lightweight and modular state management library for React applications, designed to handle various state scenarios such as **basic**, **asynchronous**, **loadable**, and **controllable** states. With support for **nested states** and seamless integrati
The npm package react-state-forge receives a total of 7 weekly downloads. As such, react-state-forge popularity was classified as not popular.
We found that react-state-forge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.