helix

hifumi123 2023-04-06T00:54:08.254369Z

Is it possible to spread in more than one props map? I want something similar to

($ component {:& props & extra-props})
In my case, props is a CLJS map and extra-props is a JS map generated by react-hook-form.

2023-04-06T01:50:18.820679Z

is there a reason you can't https://clojuredocs.org/clojure.core/merge them?

($ component (merge props (js->clj extra-props)))
or simklar

hifumi123 2023-04-06T01:55:09.767429Z

want to avoid having to js->clj at run-time only for helix to take the map and clj->js again

hifumi123 2023-04-06T01:55:19.026989Z

im aware of this approach but am looking for an alternative, if it exists, since the approach in my head seems wasteful

lilactown 2023-04-06T02:44:06.924619Z

there isn't currently a way, but helix could provide a helper function for it in the future

lilactown 2023-04-06T02:44:40.293619Z

e.g.

($ component {& (helix/merge-props props extra-props)})

lilactown 2023-04-06T02:50:17.280659Z

you could also do something like

($ component {& (merge props (cljs-bean.core/bean extra-props))})

lilactown 2023-04-06T02:50:51.953159Z

that's basically what defnc does to props passed to you component

2023-04-06T11:42:26.957299Z

Hello using helix to display a MaterialReactTable component. Is there a way to refer to that in a different component and call the table functions? Basically something like let [t ($ MaterialReactTable …] and then at the click of a button (.getAllColumns t) . Sorry if this is my misunderstanding of how react components work!

2023-04-07T21:08:11.044289Z

So you put me on the right track but use-ref fails because it’s an invalid hook call. It may be because I’m mixing reagent and helix and the let is within a reagent element. Is there a way to achieve what I’m trying to do without recreating a whole functional component? Or can I easily convert a reagent element into a functional react element?

alexdavis 2023-04-07T21:48:43.087439Z

As long as you aren’t using create-class you should be able to make it a functional component using :f> I think. Or you can use an atom as the ref, pretty sure that’s the standard reagent way, then you don’t need hooks

2023-04-09T08:18:08.748779Z

Yeah I’ve seen these. It somehow works without dereferencing which tricked me in the first place. Maybe “current” is already a view for material-react-table

2023-04-08T20:49:37.714009Z

You nailed it, :f> works. Atom didn’t for some reason. Thank you SO much!

2023-04-08T20:51:52.401389Z

Edit because you made me think: atom works, my bad, but you need to do (aget myatom “current”) without dereferencing

alexdavis 2023-04-08T21:59:25.122709Z

Hmm think you should deref if you use an atom, these are the reagent docs I was referring to https://github.com/reagent-project/reagent/blob/master/doc/FAQ/UsingRefs.md But glad the hooks way works for you 😊

alexdavis 2023-04-06T13:30:37.214779Z

you probably want to store a ref and call .getAllColumns on that instead

alexdavis 2023-04-06T13:35:15.229349Z

something like

(let [table-ref (use-ref)]
  ($ MaterialReactTable { .... tableInstanceRef: table-ref}))
how you store the ref is up to you, maybe using a context or some global store, or just pass it down

alexdavis 2023-04-06T13:35:29.502299Z

but you can then do

(.getAllColumns table-ref)

2023-04-06T13:36:24.740619Z

Thanks Alex! Let me try