Fork me on GitHub
#reagent
<
2022-07-04
>
pinkfrog10:07:52

(defn some-comp [& xs])
How can you know if (first xs) is props or some other arguments? Sounds like it’s impossible to solely based on the type. It might be the case that some argument happen to have the type of being a map, e.g., [some-comp {:not-a-prop 42} where the map is not meant to be the props. How do you address this? I can only think of like adding a meta data to the (first xs) to explicitly denote if it is a props or not.

p-himik11:07:31

It is indeed impossible. The only reasonable solution I know of is to simply require the props map and pass an empty one when you don't need to specify any props. A variation of the above solution is to add a wrapper for that component that assumes that there are no props. You'd then use either the component or the wrapper, depending on whether you need to pass some props.

pinkfrog00:07:24

Is this a common problem that most people will come across? Sounds like kinda awkward to have such an annoyance.

p-himik05:07:24

Not common at all in my experience. I always pass props myself, with the exception of plain HTML tags.

p-himik05:07:11

But it is indeed one of othe annoyances with Hiccup in general. And with anything that has optional positional arguments in a variadic function.