Fork me on GitHub
#reagent
<
2021-02-07
>
emccue03:02:48

I want to pass an actual keyword as a prop to a react component

Lu08:02:01

How about “:hello” and when you read it you just call keyword on that

emccue03:02:58

I need to pass along namespaced keywords, so not that easy

Lu08:02:56

(subs (str your-kw) 1) .. this handles namespaced kws too... then you can just call (keyword ..) on the string to have it back as it was

emccue03:02:58

such that the keyword gets "passed through"

emccue03:02:26

:> and create-element both seem to have the property get stringified in some way

p-himik06:02:48

You have to encode the props yourself - Reagent doesn't touch JS objects.

juhoteperi10:02:04

:> converts the props to JS objects automatically, doing same conversion as Reagent does with DOM nodes, snake-case to camelCase, renaming some probs and keywords to strings. create-element or :r> pass the props object as is, but you should pass in JS object as the top-level props, but inside the object you can use whatever Cljs datastructures you want.

p-himik11:02:10

You can use regular JS objects with :> as well, no? So e.g. #js {:a :b} will make sure that the component receives :b as a keyword.