Introduction
A global state manager for React.
Features
- Simple API
- Mutable State Updates
- No Context Providers
- Auto Shallow Diff Computed Props
- TypeScript Support
Installation
pnpm add @opentf/react-state
Usage
import { create } from '@opentf/react-state';
const { useAppState, setAppState, api } = create({ count: 0 });
api.subscribe(console.log);
export default function App() {
const count = useAppState((s) => s.count);
return (
<>
<p>Count: {count}</p>
<button onClick={() => setAppState((s) => { s.count++ })}>
Increment
</button>
</>
);
}
Demo
⚡ by React Sandbox
Related
-
@opentf/react-form (opens in a new tab) - A simple form state manager for React.
-
@opentf/react-sandbox (opens in a new tab) - The CodeSandbox sandpack wrapper with additional features.
-
@opentf/react-node-repl (opens in a new tab) - The Node.js REPL in a React component.
-
@opentf/std (opens in a new tab) - An Extensive JavaScript Standard Library.