Show HN: Flatstore, simplified state across ReactJS components, suck it redux (npmjs.com)

3 points by JoeOfTexas ↗ HN
I've been using this on my projects since 2019, and it's made my life so much easier sharing and reacting to state changes across components.

Redux has made life a living hell at my job trying to follow code trails for debugging.

In any case, its great for personal projects. The code is very lightweight at about 300 lines and zero dependencies.

flatstore unofficially supports history with undo/redo, but I haven't used it much. The hook `useWatch` is the latest update for function components to track state changes. If you still use legacy class components, it uses a similar HOC approach as redux for state changes.

But I recommend converting to functional components asap, as it shrinks code a lot, and you just need get/set/useWatch to do anything.

2 comments

[ 2.7 ms ] story [ 27.8 ms ] thread
Would you recommend using it in production?
Only for small projects. However, I do use it for some of my bigger projects.

`useWatch` will cause a re-render every time `set` is used on the watched key. If used wisely, you can trigger re-renders on demand, and use `get` for other data you need.

In future, I plan on making another hook that only re-renders if data has changed.