This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-26
Channels
- # architecture (2)
- # beginners (310)
- # boot (34)
- # cider (50)
- # cljs-dev (82)
- # cljsrn (1)
- # clojure (125)
- # clojure-dusseldorf (1)
- # clojure-hamburg (1)
- # clojure-italy (47)
- # clojure-russia (21)
- # clojure-spec (38)
- # clojure-uk (36)
- # clojurescript (200)
- # community-development (21)
- # cursive (10)
- # datomic (15)
- # duct (58)
- # emacs (20)
- # fulcro (10)
- # funcool (1)
- # graphql (2)
- # hoplon (6)
- # jobs (1)
- # lumo (12)
- # mount (20)
- # off-topic (14)
- # om (5)
- # portkey (43)
- # protorepl (2)
- # re-frame (31)
- # reagent (36)
- # ring (17)
- # ring-swagger (6)
- # shadow-cljs (50)
- # spacemacs (9)
- # sql (5)
- # tools-deps (28)
- # uncomplicate (4)
- # unrepl (5)
- # vim (2)
- # yada (2)
you can do it on componentDidMount if you want, or more idiomatically in the outer fn of a Form-2 component
@pesterhazy I’m not familiar with a Form-2 component, do you have any resources you can share?
note that this won't update if the props change, so if your requests depend on the props you man need to fire a request on componentWillReceiveProps/componentDidUpdate
in which case you'll need to use a React-style Form-3 component
then you should consider doing the fetch as an effect of the new location
components are often not the best place for network requests
usually what works best for me is to react to user actions with network requests
one user action of course may be page load; another may be changing the url (you can listen to those changes)
that's also the approach that the re-frame philosophy encourages
for some components, though, component lifecycle methods may be a convenient shortcut
the appropriate place for network requests is a pretty fundamental question in designing your SPA
for the record though, the load on component cycle will work fine. and can you do the presentational/container pattern if you’d like. there are advantages to not doing it that way but it will work fine. particularly if you put the url in the state object because then you get a re-render if there’s a change (and don’t have to deal with form-3)
correct! think of the route handler as "controller", and component code more as "view" parts of MVC
I agree, reagent is neutral to how you structure your app
also agree with @lee.justin.m that lifecycle methods are a good solution (especially at the beginning of the project)
one thing that is complicated about “fetch in route handler” is that you have to deal with the “loading” page while it works.
yeah but that's often inevitable anyway
plus a simple [:div]
often works...
or [:div.spinner]
sorry yea all i mean is that sometime its easier to deal with that when all the logic is in the component instead of proxying through yet more state in the giant state object
there are definite downsides to every solution i’ve dealt with for the load-on-route-change problem. unless you go full re-frame I suppose
Is there anything like a 'reagent fiddle' app available?
Klipse does that