I'm a begginner in cljs and I'm trying to use reagent in logseq plugin. A Logseq block can read html. I've tried sending a simple component:
(defn simple-component []
[:div
[:p "I am a component!"]
[:p.someclass
"I have " [:strong "bold"]
[:span {:style {:color "red"}} " and red "] "text."]])
into a logseq block, but that appears as [object object].
So I suppose I should have something that manage the react component and then update the logseq block with the html rendered by the component. How to do that?
(I've already asked on Logseq Discord)So did you get logseq to render a reagent component?
How exactly do you embed that component in a block?
And yeah, it's most definitely a question for Logseq. Your CLJS code looks just fine.
The reason for [object Object] is probably because it doesn't recognize whatever you're actually embedding as Reagent Hiccup. But the code itself is correct, there's nothing wrong with it.
Do I need to have a :require in my .cljs for reagent? I haven't seen any in examples
(-> (js/logseq.Editor.updateBlock block-uuid (simple-component))
I don't get any error when I run this, so I suppose it's working? I've also added the reacts deps in shadow-cljs.edn
I have zero clue. While I use Logseq myself, the only Hiccup-related thing that I do is embedding static Hiccup directly into blocks.
If the Logseq documentation is lacking in this regard, perhaps you can check out the sources of one of the many plugins it has.
There's a react typescript playground plugin, but I don't really understand where this is rendered
A list of plugins: https://discuss.logseq.com/t/any-samples-of-plugins-written-in-clojurescript/11931/4
edit: Solved the following with
npm i react react-dom
The documentation here should be changed to mention to also install npm packages, not or install.
https://github.com/reagent-project/reagent
I have the same problem as this user.
The required namespace "react-dom" is not available, it was required by "reagent/dom.cljs".
I do have reagent, react and react dom in shadow deps. I'.ve ran yarn. What else do I need?
https://clojureverse.org/t/the-required-namespace-react-dom-is-not-available-it-was-required-by-reagent-dom-cljs/8536