reagent

Sam Ritchie 2023-01-06T17:02:56.549059Z

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>?

dvingo 2023-01-06T17:18:07.374849Z

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-himik 2023-01-06T17:19:31.267629Z

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

dvingo 2023-01-06T17:19:35.839659Z

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

p-himik 2023-01-06T17:20:09.758259Z

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

dvingo 2023-01-06T17:21:43.083529Z

yea for sure

dvingo 2023-01-06T17:22:00.703049Z

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

Sam Ritchie 2023-01-06T17:44:57.205099Z

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

Sam Ritchie 2023-01-06T17:45:31.222519Z

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