Fork me on GitHub
#reagent
<
2022-01-26
>
Chase16:01:51

for props that don't have a label such as isRequired should I assume it should be put into the props map like: {isRequired: true} or more likely {is-required: true}? What about setting defaults? Right now I'm just doing something like (or (:title props) "My Title") but not sure if there is a more official way.

p-himik18:01:40

Yes, flag attributes have boolean values in Reagent. {:is-required true} and {:isRequired true} are both fine, but it's more common to use the former, the so-called kebab-case. Regarding the defaults - it depends. If it's "use the value if the key is not in the map", then you can either destructure the property somewhere with :or or use the second argument to either get or a keyword function, like (get props :title "My Title") or (:title props "My Title"). And if it's "use the value if the current value is nil" then your approach is the right one.

Chase22:01:11

Ahh, I forgot about :or , thank you

👍 1