This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-01
Channels
- # announcements (3)
- # babashka (20)
- # beginners (77)
- # calva (27)
- # cider (5)
- # clara (3)
- # clj-kondo (9)
- # cljs-dev (4)
- # cljsrn (5)
- # clojure (26)
- # clojure-europe (32)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-uk (5)
- # clojurescript (25)
- # clojureverse-ops (4)
- # core-async (49)
- # cursive (15)
- # data-science (1)
- # datahike (4)
- # datomic (3)
- # docker (1)
- # events (1)
- # helix (5)
- # holy-lambda (3)
- # introduce-yourself (1)
- # jobs (1)
- # kaocha (2)
- # lsp (15)
- # malli (42)
- # off-topic (18)
- # pathom (18)
- # pedestal (12)
- # polylith (7)
- # rdf (1)
- # re-frame (22)
- # reitit (2)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (33)
- # shadow-cljs (85)
- # spacemacs (3)
- # vim (12)
- # xtdb (29)
Question, given that a ratom is the way reagent replaces React’s useState
, what is the reagent/re-frame way of doing the same as React/useEffect and React/useCallback?
You can use them directly. For example: https://github.com/reagent-project/reagent/blob/c214466bbcf099eafdfe28ff7cb91f99670a8433/examples/functional-components-and-hooks/src/example/core.cljs#L12-L22
But note that the component has to be used as a functional one, via :f>
.
I often see things that you'd put in useEffect
be put just in the render function itself. But AFAIK the render function can be called multiple times (no clue in which scenarios) and thus such code can be called more than needed.
As for the useState
- form-2 components replace it, along with reagent.core/with-let
.
This section of the re-frame documentation addresses some of the same issues that useCallback was created for: https://day8.github.io/re-frame/on-stable-dom-handlers/#but-wait-functions
For useEffect you can also use create-class and the old ‘component-did-update/mount’ style
I have a global react ref I need to store for one of those pop-over UX message controllers (<Toast ref={toast} />) .. previously I've stored refs in atoms local to the component because I havnt needed to span components (they've been local controllers for popopver menus or similar) .. what should I do with this ref? can I store the ref in the reframe db?
send the reference a message e.g. toast.show{"type": "error" "message": "Backend error 500: something"}
I guess the reference is just a JS element so it should be trivial to just store it in the db?
Sounds like you can store something like :toast-data
in app-db
and call toast.show
in a re-frame wrapper that would be subscribed to :toast-data
.
Yeah, so far I've gotten the element (when logged, its definitely the 'Toast' object I'm looking for)
How would I achieve that? I have the
[:> Toast]
In a parent component, and the events all queued up to set the fields to the db, and I have the subscription wired up and working, does the parent component actually bind the sub? Ive been googling for awhile and cant find how to glue it toghetherI would wrap Toast
in my own toast
component that accepts the data that needs to be shown as an argument. It has to be a form-3 component that calls toast-obj.show
on a mount and on each update.
How you get that toast-obj
object depends on the API. If it absolutely must be a ref, then you do have to use a ref - but it won't travel outside of that component.
basically a global reagent atom seperate from re-frame for that part of our state, and we have an :fx that talks to the “notification golem” which has some view mounted specifically for it