@shtse8/fluxus
Version:
A functional, reactive state management library for TypeScript inspired by Riverpod.
95 lines (73 loc) • 2.29 kB
Markdown
A functional, reactive state management library for TypeScript inspired by
Riverpod.
[](https://badge.fury.io/js/fluxus)
[](https://opensource.org/licenses/ISC)
Fluxus aims to provide a TypeScript-native state management solution inspired by
the best ideas from libraries like Riverpod, Jotai, Zustand, and Valtio, while
emphasizing functional programming principles.
**Core Principles:**
- **No Pre-registration Dependency Injection:** Dynamically create and use
providers without a central registry. Optimal tree-shaking.
- **Functional Programming:** Embrace function composition, pure functions, and
immutability.
- **Fine-grained Reactivity:** Automatic and precise dependency tracking.
- **Robust Lifecycle Management:** Clear resource cleanup APIs and automatic
lifecycle handling.
```bash
npm install fluxus
yarn add fluxus
pnpm add fluxus
```
```tsx
import React from "react";
import {
ProviderScope,
stateProvider,
useProvider,
useProviderUpdater,
} from "fluxus/react-adapter";
// 1. Define a provider (just a function)
const counterProvider = stateProvider(0);
// 2. Wrap your app (or relevant part) in ProviderScope
function App() {
return (
<ProviderScope>
<CounterDisplay />
<CounterControls />
</ProviderScope>
);
}
// 3. Use providers in components
function CounterDisplay() {
// Reads the value and subscribes to updates
const count = useProvider(counterProvider);
return <div>Count: {count}</div>;
}
function CounterControls() {
// Gets the updater function (doesn't cause re-renders itself)
const updateCounter = useProviderUpdater(counterProvider);
return (
<div>
<button onClick={() => updateCounter((c) => c + 1)}>
Increment
</button>
<button onClick={() => updateCounter((c) => c - 1)}>
Decrement
</button>
</div>
);
}
export default App;
```
(Full documentation coming soon!)
(Contribution guidelines coming soon!)
ISC