Managing State with Re-Frame

The most popular Reagent-based framework is re-frame. Re-frame places all its state in one global atom which it calls the app-db. The only way to read from the app-db is using re-frame subscriptions, and the only way to write to the app-db is by dispatching re-frame events. Note that even though the app-db can only be accessed this way, we can still include regular Reagent atoms in a re-frame application and manage them ourselves.

Let’s get re-frame set up in our guestbook application so we can see how it works. First, just like we did with cljs-ajax, let’s add it to our project’s dependencies:

 [cljs-ajax ​"0.8.1"​]
 [org.clojure/clojurescript ​"1.10.764"​ :scope ​"provided"​]
 [reagent ...

Get Web Development with Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.