Reagent not reacting

I have my store file that has

(def state (atom {}))

(defn remove-token []
  (swap! state dissoc :token)
  (swap! state dissoc :payload)
  (cookies/remove! "token"))

(defn set-token [token]
  (swap! state assoc :token token)
  (swap! state assoc :payload (token-payload token))
  (cookies/set! "token" token))

(defn isGuest? []
  (nil? (:token @state)))

Then my function to draw the logged out menu is

(defn render []
      (store/isGuest?) (guest-menu)

and has some nested stuff that guest-menu calls.

When I call store/set-token from my login form it works fine, the token gets set and my menus change to the logged in version. For logout, I have a button that removes the token, which should cause the menus to revert back to the logged out version.

My store/remove-token function gets called, but the page doesn’t get redrawn. If I refresh the page, everything goes to what it should be. Any ideas what I’m doing that’s causing it to not react to the token being removed?

With the login, I’m not sure if it’s working because it’s updating right or because login changes pages (it goes from a form back to a normal page).

The state atom you declare, is it a reagent.core/atom or a standard Clojure atom? The former is the only thing that will causes a rerender on change.

1 Like

Shoot, yep. Wrong atom. :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.