logoalt Hacker News

dwoldrichyesterday at 9:09 PM0 repliesview on HN

I'm not a fan of state management in React apps, and it took me a long time to come to peace with it. What I landed on that works with the system rather than against is useContext at the page level containing Jotai atoms that wrapper Immer-managed objects representing the page states that get passed through the component tree as props.

I built my own action framework that gives me the ability to use Jotai getters to read atom data, launch asynchronous javascript, and then write to atom data via Jotai setters without ever having to fuss with useEffect myself. Jotai just handles the messy state transition work. My components used to be a jumble of DOM event handler, business logic, and markup, and now the business logic is all extracted to the separate action components.

React makes it hard to test business logic in isolation, and I am hoping my action framework could do a better job of that.