This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-06
Channels
- # announcements (18)
- # asami (14)
- # aws (5)
- # babashka (58)
- # beginners (32)
- # calva (12)
- # cider (29)
- # clj-kondo (8)
- # cljfx (8)
- # cljs-dev (4)
- # clojure (101)
- # clojure-europe (54)
- # clojure-germany (5)
- # clojure-nl (8)
- # clojure-serbia (8)
- # clojure-spec (12)
- # clojure-uk (8)
- # clojurescript (24)
- # cursive (3)
- # datomic (17)
- # docs (2)
- # etaoin (12)
- # events (1)
- # fulcro (1)
- # google-cloud (2)
- # jobs (1)
- # jobs-discuss (6)
- # lsp (65)
- # luminus (2)
- # malli (10)
- # meander (4)
- # nrepl (1)
- # off-topic (112)
- # onyx (2)
- # pathom (6)
- # polylith (14)
- # re-frame (9)
- # reagent (36)
- # reitit (13)
- # releases (2)
- # remote-jobs (5)
- # rewrite-clj (12)
- # shadow-cljs (70)
- # specter (2)
- # startup-in-a-month (1)
- # xtdb (14)
Hi :spock-hand:
Is there any good practices about components local state managing? Is it ok to pass ratom
into event and then in callback event effect clean it:see_no_evil:
(rf/reg-event-fx :event
(fn [_ [_ state id]]
{:mutate [... id [:on-success state] [:on-error state]]}))
(rf/reg-fx ::reset-input #(reset! % nil))
(rf/reg-event-fx :on-success
(fn [_ [_ state result]]
{...
:reset-input state}))
(defn component [id]
(r/with-let [state (r/atom nil)]
(let [{:keys [loading? value visible?]} @state
on-submit #(rf/dispatch [:event state id])]
... [:input {:value value}] ... [:button {:on-click on-submit}])))
Keep such local state in app-db
feels bad - than i need to make sure that it was cleaned.
And pass callback into event feels bad, to call it above re-frame
dsl.Passing a callback would IMO be better.
In that case, there would be a more generic :call
effect instead of the :mutate
effect.
Alternatively, just don't use re-frame at all for such a component. Just treat it as if you were using pure Reagent.
3