Fork me on GitHub

one of the problems I’ve encountered when developing with reagent is that it makes it really attractive to use global state vars in order to avoid props drilling


take a look at re_frame. subscriptions make this a non-issue, and the framework as a whole adds a whole lot more power to boot


no, re-frame makes it worse by forcing you to use a single global state var for everything 😉


the anti pattern is not scoping your state to the tree being rendered


if you leave your data in one giant map as data, not as a view tree, your app will remain much more flexible to extension and growth


by referencing a global var, it makes it hard to do things like render a stateful component in a devcard. unit testing also becomes much harder


I also disagree with that, but that's somewhat unrelated 🙂 a giant map does not compose well


but it's unrelated; redux uses the single-app-db while also allowing one to scope their app-db to a particular render tree


e.g. you can have multiple instances of an app running on one page. or do server-side rendering without worrying about bleeding data between requests


global vars (and a giant map for state) make certain things easier, but they have serious downsides once you start to scale


in raw React this is supposedly fixed by using Context, but using render props is super verbose and awful, especially when you’re consuming multiple context


the new React Hooks API makes it REALLY ergonomic in a CLJS setting. very similar to using reframe, but your state is scoped to the render tree!!


in fact, here’s how to use the new useReducer hook to start building a tree-scoped re-frame clone 😄