Fork me on GitHub
#fulcro
<
2022-04-13
>
aratare02:04:21

Hi there. I’m going through the docs and noticed that in section 10.2 (React Lifecycle and Load), it is stated that

React lifecycle and load may not mix well.
I have an application where I need to load data on page load. Where should the initial data fetch operation be placed, if not lifecycle? One place I can think of is will-enter, but that requires a router and I may not have every component hooked up to a router. Thanks in advance 🙂

aratare03:04:38

It’s also stated that I should be doing some checking before sending a load request. Currently the data fetched will just replace whatever is in the current state so it’s fairly simple. I just want to make sure if there’s any other recommended ways that Fulcro users tend to use.

dvingo03:04:33

if it's when the app boots you can issue data fetches via client-will-mount or client-did-mount https://github.com/fulcrologic/fulcro/blob/0170fd1f7b10b75cfb822c92f052387c40999c63/src/main/com/fulcrologic/fulcro/application.cljc#L178 the other spot to typically issue data fetches in javascript react is in :componentWillMount or :componentDidMount or the hooks equivalent. I think the section is just calling out the fact that mounting/unmounting of a component can occur more often than you anticipate, or could in the future when you update the code.

👆 1
dvingo03:04:23

most of the time you will have event that triggers a load, so you should think about how you can make that happen - sounds like using the dynamic router is what you'd want here, using will-enter like you mentioned

aratare03:04:05

Will have a go at it. Thanks for the help 🙂

aratare03:04:42

DR may be what I want here since I need to occasionally reload data as well thinking-face

Jakub Holý (HolyJak)07:04:08

> load data on page load I would do that in the fn called when the app is starting, such as my https://github.com/holyjak/minimalist-fulcro-template-backendless/blob/main/src/com/example/client.cljs#L9 If you risk running it too often then check that it does not exist already. https://github.com/holyjak/fulcro-billing-app/blob/main/src/shared/billing_app/ui/billing/ui.cljc#L392. It is ok to use will mount. A possible problem is cascading load - when the component loads and renders, a child will start mounting and load, ... so you have a sequence of loads which is slower then loading all at once / in parallel. That is one of the problems that DR and will-enter solves. But it might not apply or matter to your case.

Benjamin C20:04:57

Is there a proper way to get the pathom env so I can run server-initiated mutations or queries? Digging through RAD's form code I found this:

(def save-form
     {:com.wsscode.pathom.connect/mutate (fn [env params] (save-form* env params))
      :com.wsscode.pathom.connect/sym    `save-form
      :com.wsscode.pathom.connect/params #{::id ::master-pk ::delta}})
Which seems to translate somehow into a callable function that calls the passed mutate fn with the env, but I haven't yet figured out where or how this happens.

sheluchin20:04:08

You can create your own env with whatever you need in it.

🙌 1
Benjamin C20:04:03

Oh! 😂 Thanks. Maybe I should ask questions sooner, I've been trying to figure this out for hours.

sheluchin20:04:17

Hope it helps. At one point I too was under the impression that there should be just one Pathom env and it should be retrieved to interact with Pathom. Just make them as you need.

Benjamin C20:04:17

Yep, that did the trick. Thank you!

👍 1
tony.kay20:04:00

Release 3.5.18 of Fulcro. Adds support for :fulcro/warnings? false in component options to turn off warnings when you are happy with a component, but Fulcro warns you about it. Also changed nc so that it sets that option so you won’t see warnings about dynamically generated components. You can get them by changing it to true in the options when you call nc if you want them.

👍 4
❤️ 1