This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-04
Channels
- # architecture (20)
- # aws (8)
- # beginners (13)
- # boot (9)
- # cider (80)
- # cljs-dev (69)
- # cljsrn (7)
- # clojure (243)
- # clojure-dusseldorf (8)
- # clojure-italy (5)
- # clojure-norway (3)
- # clojure-poland (57)
- # clojure-russia (10)
- # clojure-shanghai (2)
- # clojure-spec (11)
- # clojure-uk (50)
- # clojurescript (198)
- # core-async (11)
- # crypto (2)
- # cursive (14)
- # datomic (17)
- # figwheel (8)
- # garden (7)
- # hoplon (8)
- # incanter (4)
- # jobs (1)
- # leiningen (1)
- # liberator (38)
- # lumo (28)
- # om (55)
- # onyx (10)
- # pedestal (13)
- # perun (20)
- # re-frame (1)
- # reagent (16)
- # ring-swagger (9)
- # spacemacs (11)
- # test-check (9)
- # unrepl (43)
- # untangled (163)
- # yada (8)
I was experimenting with having local component state for a “toggle” sort of button. What I’m seeing though is that when I hit the “back” button on the browser, this state is reset each time.
I’m not positive I want to even have this sort of local state, but I was surprised by this behavior and was just trying to understand it.
I know this isn’t a lot to go on. I’m making a single page app. I’m just using url hashes and client-side routing to change the view content
so the back is just triggering a History change back to a former hash. I define local-state components like:
(defn local-state-component []
(let [state-toggle (r/atom false)
toggle-change #(swap! state-toggle not)]
(fn [props]
<do things with the @state-toggle here>)))
my app is just something like:
(r/render (if (= :main (:active-view @app-state)) [local-state-component] [something-else]) (.getElementById js/document “app”))
So basically, when the :active-view
changes (just a hash change in URL) from local-state-component
, to something-else
, back to local-state-component
, the local state is reset to it’s initial value.
if the component gets destroyed, its state is lost
if you want to preserve the state of the component, why use local state?
@pesterhazy I started to realize that after I asked this question
and I don’t actually think I want local state, I transitioned away from it. I was just making sure I understood the general problem.
Since this component is removed completely from the newly rendered (v)dom though, I guess it makes sense that when it comes back again, it is all new.
I've wrapped a react component using adapt-react-class
. The component itself has a very conservative componentWillReceiveProps()
, which means that it doesn't actually end up rerendering when I change the reagent atoms I have it depend on. I think it's possible for me to add a watch to that ratom and use that to force an update, but I'm not sure how to hook that up. Any pointers?
If it helps, here is my code: https://github.com/Zensight/reagent-slider/blob/master/env/dev/cljs/reagent_slider/dev.cljs#L23
What I'm trying to make happen is for that reset!
to rerender the component. It doesn't because the wrapped React component intentionally ignores changes to :defaultValue
(as I understand it, anyway), so I need a hook to say "ok, but just recreate yourself anyway"
and i am open to responses like "you are doing this all wrong"