Fork me on GitHub
#fulcro
<
2023-12-19
>
Eric Dvorsak20:12:12

I have a defsc with a route-segment [:course/id], :course/id is also the ident Now this components has 2 tabs which I'm trying to implement with a defrouter, but how can I pass the :course/id down?

Eric Dvorsak21:12:33

ok so I got it to work with a combination of will-enter on the child and pre-merge on the parent, but I have no idea what I am doing. I was trying to follow these two resources but I have a hard time understanding. https://book.fulcrologic.com/#_composing_the_routers_state_into_the_parent https://blog.jakubholy.net/2020/fulcro-divergent-ui-data/#_inserting_a_stateful_ui_component_between_a_parent_child_entities @U0522TWDA it would be awesome to have a working example of this one and maybe some extra explanation

tony.kay01:12:06

It's a little dangerous to have a route segment that doesn't include some sort of unique constant component, because doing so means that other siblings that do the same thing will then be ambiguous. That said, route parameters are passed as the params argument to dynamic routing calls. They will come to will enter as strings, independent of the type that you would actually like. I believe the dynamic routing chapter covers all of this

Jakub Holý (HolyJak)10:12:09

+1 to what Tony said. You most likely want rather something like :route-segment ["course" :course/id] on the parent component. I assume the problem you are facing is that the child tabs have route segments something like ["tab1"] and ["tab2"] ? I do not remember whether route-params in the tab’s :will-enter have the full route params (thus including the parent’s :course/id or not). Do they? I believe that I have previously solved it by passing an ID like this from a parent component down to descendants as a computed prop, see :organization/organization-number in https://github.com/holyjak/fulcro-billing-app/blob/main/src/shared/billing_app/ui/billing/ui.cljc#L497-L498

Eric Dvorsak20:12:42

@U0522TWDA interestingly it is called more than once and at first the params that are part not part of the component segment are not there

Mark Wardle20:12:11

Am I right in thinking that computed properties are only needed for components that have an ident and query? For components that are just glorified defns producing only UI data, is it fine to pass properties such as functions and whatnot in the main props, or should they be declared as computed props? I see the fulcro template uses defn for this kind of thing, so should I use that rather than defsc?

Eric Dvorsak21:12:51

that's a great question I was wondering the same!

tony.kay01:12:17

Correct. Computed allows fulcro to keep track of which things it found for the component versus which things you added in. If fulcro did not provide any of the props, then there is no need to separate them.

tony.kay01:12:12

Optimizations that Target rendering at components with idents need to be able to generate new props that include whatever the parent last passed to them. If the computed props are not marked, then such refreshes will look as if the parent add-ons disappear during an optimized refresh

👍 1