Fluent, immutable React local state that just makes sense.
A tiny (~2.4kb), proxy-based React hook for deeply nested, reactive state, computed reactive state and built-in effects — zero boilerplate, no reducers, no magic.
Or with yarn:
⚡ Live demo on CodeSandbox (state & effect) »
⚡ Live demo on StackBlitz (state, compute & effect) »
I built fluent-state because I wanted a React state hook that:
- Replaces useState, useReducer, and useEffect with a single, fluent, and reactive API
- Feels like plain JavaScript with getter/setter functions
- Updates immutably and efficiently under the hood
- Tracks dependencies automatically, no manual arrays
- Handles deep nested objects and arrays naturally
- Avoids magic, globals, or complex APIs
- Fluent getter/setter API (state.user.name("Alice"))
- Immutable updates, fully React compatible
- Auto-tracked effects with zero boilerplate
- Works flawlessly with nested objects and arrays
- Reactive computed state with compute for derived values
- Tiny bundle size (~2kb)
- Full TypeScript support with accurate typings
fluent-state uses JavaScript Proxies — but not to wrap your entire state object directly.
Instead, it wraps tiny getter/setter functions that correspond to specific paths inside your state. These proxies:
- Wrap just the accessors for each path, completely separate from the actual state object
- Are lightweight and cached for excellent React performance
- Have no magic — just normal JavaScript behavior
This means:
- You call fluent getter/setter functions like state.user.name("Alice")
- Immutable updates happen internally without mutating the original state
- Effects track which getter functions you use — no manual dependency arrays needed
In short: fluent-state’s proxies wrap functions representing paths, not the state object itself — keeping everything simple, predictable, and reactive.
Besides effect for side-effects, fluent-state also provides the compute function to create derived, reactive state that automatically updates whenever its underlying dependencies change.
- compute automatically tracks which proxy getters you call
- The computation re-runs whenever any of those dependencies change
- It’s the ideal replacement for useMemo + useEffect combinations
- compute returns a function you call to read the current computed value
This example shows how useFluentState manages deeply nested arrays and objects with a fluent, immutable API, while effects automatically track dependencies and run only when needed.
Q: Why do I need to call state fields as functions like state.user.name()?
A: This getter function pattern allows automatic dependency tracking and controlled immutable updates, keeping your React components efficient.
Q: Can I update nested state immutably without writing verbose code?
A: Yes! useFluentState handles immutable updates under the hood, so you can write concise updates like state.user.address.city("New City").
Q: How do effects know when to re-run?
A: Effects track which state getters you call during execution. They only re-run when those specific values change.
Q: Does this work with arrays?
A: Absolutely. You can update arrays immutably and track changes as shown in the todo example.
- ✅ Fully working effect system with automatic dependency tracking
- ✅ Support for deeply nested objects and arrays
- ✅ Reactive computed state with compute
- ⏳ Persist plugin for saving state to localStorage or similar
- ⏳ Devtools integration for easier debugging
- ⏳ Optional global/shared state support
- ⏳ Performance optimizations and bug fixes
fluent-state is a stable and reliable library with a solid foundation.
While it currently lacks automated tests, it has been carefully designed and tested manually.
Adding automated test coverage is on the roadmap to ensure ongoing quality and reliability.
Contributions to help expand test coverage and improve robustness are very welcome!
Contributions, feedback, and ideas are welcome! Feel free to open issues or PRs.
MIT © Marcel Bos
Built with care by Marcel Bos
.png)

