Fork me on GitHub
#reagent
<
2023-01-06
>
Sam Ritchie17:01:56

I’ve found myself doing this for function components:

(defn FunctionComponent* [opts] ,,)

(defn Component [opts]
  [:f> FunctionComponent* opts])
is there a cleaner way to define a function component (that can use hooks etc) in one shot, without the extra wrapper to pass :f>?

dvingo17:01:07

You can just invoke the function as reagent will leave non-vectors&non-functions untouched (https://github.com/reagent-project/reagent/blob/e67d4f8804c109868469d6e81ecd7184cf707575/src/reagent/impl/component.cljs#L100)

(defn Component [opts]
  (FunctionComponent* opts))

p-himik17:01:31

The [:f> ...] part is a vector though.

dvingo17:01:35

oh i see now - that just "moves" the problem to every caller needing to know that

p-himik17:01:09

Apart from that, it also probably prevents ratoms from working properly in such a function component.

dvingo17:01:43

yea for sure

dvingo17:01:00

another option is enabling function components as the default output: https://github.com/reagent-project/reagent/blob/master/doc/ReagentCompiler.md

Sam Ritchie17:01:57

@U051V5LLP in this case I am writing a library of components, so I would like to provide something easy for the user

Sam Ritchie17:01:31

the “solution” I posted before is definitely the nicest thing for the end user, but I have to define both of these components, and explain why there are two or hide one from the user