This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-09
Channels
- # babashka (63)
- # beginners (97)
- # biff (11)
- # chlorine-clover (5)
- # cider (46)
- # clara (2)
- # clj-kondo (34)
- # clojure (65)
- # clojure-austin (1)
- # clojure-europe (9)
- # clojure-france (10)
- # clojure-italy (11)
- # clojure-nl (3)
- # clojure-spec (29)
- # clojure-uk (5)
- # clojuredesign-podcast (1)
- # clojurescript (56)
- # clr (6)
- # component (17)
- # conjure (5)
- # core-typed (5)
- # cursive (23)
- # data-science (5)
- # datahike (3)
- # dirac (3)
- # emacs (20)
- # fulcro (17)
- # graalvm (10)
- # graphql (8)
- # helix (99)
- # honeysql (7)
- # jobs-discuss (9)
- # juxt (9)
- # leiningen (14)
- # malli (3)
- # meander (6)
- # off-topic (77)
- # pathom (7)
- # re-frame (12)
- # reagent (8)
- # reitit (10)
- # restql (1)
- # shadow-cljs (22)
- # spacemacs (10)
> I'm looking for a re-natal-like template that works with shadow-cljs rather than figwheel https://github.com/flexsurfer/ClojureRNProject
Hi, all
I'm working on my first re-frame project, and I've been looking all over for a set of best practices in writing forms in re-frame . Right now, 3 main approaches are available:
1. using a reagent/atom
or a plain atom
to retain values entered in the form, and update!
-ing it in element :on-change
2. using the app state and dispatch an event that changes db
, updating and maintaining values there until it's time to submit.
3. Libraries (below)
I was wondering if there is a better solution. I'm aware of different libraries, (`re-form`, re-frame-form
, reagent-forms
, duff
, fork
, etc.) but these do not seem to be vetted, largely used libraries.
I searched, but never saw a general "best practice" guide, and as of now, my best solution seems to be reagent/atom
, since it is versatile and adds minimum noise to the codebase.
I was hoping if your experience is different, or if you can direct me to practices that I wasn't able to find.
Thank you,
-Ashkan
In my experience, forms are the hardest thing to get right in a Re-frame/Reagent project. I’ve settled on the following approach:
1. Create low-level, stateless Reagent components that accept a value to display and an on-change
/`on-click` callback function.
2. Create a higher level form component that manages a map of values in a reagent/atom
and takes a data structure that specifies which components to display. This form component renders the lower-level components while wiring their value and on-change properties to its value atom.
3. The form component can provide a submit button, where it runs any validations you need against values in its ratom, storing error messages back in the ratom or calling a callback with the values if everything is valid.
Sorry I don’t have any public code that I can point to but happy to answer any questions you have.
You should also look at re-com: https://github.com/day8/re-com
thanks @U0DTSCAUU this is great help
If state is local to your form component r/atom is ok. But beware that the state is lost if the component unmounts. If you need the form state in other components or views I would stick it to app-db. I’ve had success with keeping my form-state in app-db. I only use ratoms for really local and usually small things.