Is there a way to create unnamed components? something like
(def components-by-type {"typestring-passed-by-js" #($ GeneralInputComponent {:geninputprop1 "config-str-for-typestr-and-geninput" :geninputprop2 "another-config-str-for-typestr-and-geninput" :geninputpropn "andanother-config-str-for-typestr-and-geninput" & %})}
But the map components-by-type has dozens of entries. I found that generally speaking I have less generalinputcomponents and typestrings and configs for typestrings than how many names I have to figure out for reactcomponents, so I would like to avoid doing this work 🙂#(GenInp (clj->js (merge {:cfg "cfgstr"} (js->clj % ))))
seems to work X)
I am going to pretend it's fine : D
I think I saw a fnc macro
maybe internally?
yeah, it's private.
and the above pattern breaks because I should only convert the top layer
It's a conundrum because I don't know how to come up with descriptive names for all these components, eventually it should be configured automatically so it will be even harder. It feels bit like The Kingdom of Nouns
Would be nice to see the first example here in helix: https://reactjs.org/docs/hooks-state.html#hooks-and-function-components
https://github.com/geraldodev/react-form-hook-test/blob/master/src/main/app/core.cljs#L60 helix + malli + react-form-hook example
I’ll think about how to make fnc friendly enough to make public
@lilactown is there no way currently to achieve this? I am unsure even - at the moment, having thought about relatively shortly - how to achieve with just react api, so that I can use helix components.
There’s not a public api for it in helix
You can always use a fn:
(fn [props] ,,,)
props
will be a JS obj so you’ll need to use interop or convert it to a CLJS map-alike
That’s all defnc really does
@lilactown I think in the above example, I did use a function, no?
and I am saying that because of the clj->js conversion, I am getting erros that Uncaught Error: [object Object] is not ISeqable
sadly these erros break everything, and there are zero good stacktraces, I don't even know which level it happens...
I’ve pasted an example I think the last time you asked this. Not at a computer rn so I can’t type it out
@lilactown sorry, I didn't want to trouble you : ), I will go back, but I don't remember me asking this specific question, and the last time I asked similar you specifically told me to use a named function, which is the matter of my current question, I would like to avoid having to come up with names for these functions.
you can do this for now:
(fn [-props]
(let [props (cljs-bean.core/bean -props)]
,,,))
thanks @lilactown, bean seems very useful. Btw, the issue was I think that I wanted to use (map) over a hashmap, because that works in clojure, but not with a js object, but I passed this hashmap through props...
in js I used .entries() to map over key/value pairs
(map #(let [[_ [key value]] %]
($ MenuItem {:value key :key key}
($ "em" value)))
(.entries js/Object items)))))))
Maybe there is a more clojure-i way 😄actually, I am just doing everything wrong. I wish I had a hammock