Redux Alternative
taverne.surge.sh
taverne.surge.sh
You can play around with a demo here https://codesandbox.io/s/galactic-context-demo-eqkrp
I also created a library for state management including Context, the main goal as well was not to rerender everything when a fragment of a Context changes (which is IMHO the main limitation of using Context):
const Counter = () => {
const [counter, setCounter] = useStore('counter');
const onClick = () => setCounter(counter + 1);
return <button onClick={onClick}>{counter}</button>;
}
// ...
const App = () => (
<Store counter={0}>
// ... App
</Store>
);
There's probably dozens like ours! It's fun, simplifies and improves development and it's not so heavy-handed as Redux (+ all the concepts behind).I appreciate the effort and technical prowess involved, but quite frankly Redux is bad design to begin with. Dan Abramov is a smart guy but does not think clearly enough to be allowed to design APIs.
Not saying MobX or the like are any better, but we need clearer heads approaching this problem with solutions that border on one-liners. We are storing some stuff in a global for Christ sakes, can’t we simplify all of this out of the reducer/observer pattern?
I’m depressed the marketplace of ideas has not jettisoned Dan Abramov’s ideas (the reducer pattern ended up in core React).
We are all better than this.
I’m working on a somewhat complex app and for a long time was sticking to plain useState and contexts, and lately I’m finding that moving it to a reducer (plain React, no Redux) has positive effects on architecture.
That said, the devil’s in the details—I personally think the approach is sometimes misused, including sadly certain tutorial materials. I’m reasonably new to reducers though.
zustand inspired me a lot to create the custom hooks for La Taverne, and you can also create your {store, dispatch} to use anywhere without React (and providers)
The goal is to keep Redux original power and simplicity, removing the headaches of addons like Redux-thunks or Reselect.
But Redux Toolkit is precisely among the reasons that led me to this new lib `La Taverne`:
Redux core has this awesome Flux basics, but it's deliberately unopinionated: you need addons and toolsets to complete your needs (Toolkit, Thunks, Reselect, Saga etc)
All of them add more setup, specific API, weight to your project...
I wanted a lighter solution to handle my Flux architecture.
La Taverne means to be standalone, providing essential Flux tools: async actions, immutable reducing, isolated external state.