Fork me on GitHub
#helix
<
2021-05-09
>
xlfe12:05:04

(Is there?) What's the recommended way to avoid passing props down to "native" components. Eg (defnc typography-attr [{:keys [datascript-db eid attr] :as props}] (let [[text _ db-sync _] (change-watch datascript-db eid attr)] ($ Typography {style (when db-sync #js{:animationName "change-notifier"}) & props} text))) ($ typography-attr {:variant "h6"})

xlfe12:05:26

Which gives errors such as "Warning: Invalid attribute name: table/dId"

xlfe12:05:26

I found this discussion https://clojureverse.org/t/destructure-map-keys-and-also-rest-of-the-map/3988/13 - but I was wondering if I'm missing something easier that helix already recommends? even a convention such as putting all the data behind a single keyword eg :app/data or something?

Aron12:05:48

this looks like something that interests me but being a cljs beginner, don't quite understand everything. So I apologize if I misunderstand, but isn't this about selecting the appropriate keys from the state (be it props or context) for the appropriate component?

xlfe23:05:21

yes correct. that discussion is a figuring out a macro to avoid having to do the dissoc props :problem :keys that lilactown suggests

Aron00:05:26

i have not yet come up with a better idea than statically storing queries on the components themselves

geraldodev13:05:49

@felix do you have many datascript-dbs ? that table/dld comes from it ?

xlfe23:05:06

just one. each "view" has a datascript instance which manages state. the table/dId is a refence to the datomic server side eid. the problem here is that React complains about any prop that has a slash in the name, so I have to remember to dissoc all props that I have passed down the component structure before rending the native components (at least in the cases where they need spread props, eg the typography example I had above).

lilactown15:05:47

IMO being explicit about what props you’re passing to your Typography is better than forwarding all props

Aron15:05:06

so that's what I thought

lilactown15:05:14

But in some cases you can also dissoc the few props you know are causing issues:

($ Typography
   {:style ,,,
    & (dissoc props :datascript-db :eid :attr)}
   text)

Aron15:05:30

as long as these are not nested

xlfe23:05:09

thanks @lilactown - makes sense