@dominicm in cljs you can always delegate the body of the method to a function, and when this functions is re-evaluated it would also take effect in the class. Not sure if I get you want.
Sure 馃檪 Clojure does this automatically under the hood for you with gen-class, to allow you to do this without doing it manually!
It would be cool if the new shadow classes also did that.
Hi everyone.
How can i refer defnc in helix.core namespace when it is not define? (ns my-app.core
(:require [helix.core :refer [defnc $]]
[helix.hooks :as hooks]
[helix.dom :as d]
["react-dom" :as rdom]))
lgtm
but I am not sure I get your full meaning, what is 'not define'?
i cant use the defnc.
(defnc greeting
"A component which greets a user."
[{:keys [name]}]
;; use helix.dom to create DOM elements
(d/div "Hello, " (d/strong name) "!"))
(defnc app []
(let [[state set-state] (hooks/use-state {:name "Helix User"})]
(d/div
(d/h1 "Welcome!")
;; create elements out of components
($ greetings {:name (:name state)})
(d/input {:value (:name state)
:on-change #(set-state assoc :name (.. % -target -value))}))))
It was refer from the helix.core namespace but defnc doesnt exist there.
I can use the $ but not defnc in (:require [helix.core :refer [defnc $]]). I look at the helix.core.clj and search the entire namespace but I cant seem to find defnc anywhere.
Not a bother at all. Editors are not always great at analyzing code. Sometimes you have to tell them more information. Sometimes they just aren't super smart. Generally I'd just advise to not worth so much about what the editor understands. Worry about the running program itself :)
What is the actual error you get when you try to run your program? I see the screenshot of your editor giving red squiggles. That could be an editor issue. Does it actually throw errors when you run the program?
Can I use defhook to define a multi arity hook? Like this https://stuartsierra.com/2015/06/01/clojure-donts-optional-arguments-with-varargs ?
I seems that I just fix itself after I restart build. I doesn't throw an error only warning.
I made to work now thanks.
It still confuses me though. Why I am getting the helix.core.cljs instead of helix.core.clj? That is why when I control click the helix.core it take me to the cljs file which doesn't contain the defmacro defnc because it was implemented in helix.core.clj
What editor are you using? That is the behavior of your editor.
I think it does work but only accidentally
I'm with jimmy; it sounds like you're talking about how your editor behaves with helix and defnc
, not how your app is building and behaving?
it looks like you're using VS Code, which I know defaults to using clj-kondo as its linter. clj-kondo does not understand defnc
by default
: D
sounds promising
Im using vscode. But the program works though. I got the display on localhost correctly. Sorry for bothering. I am just programming for fun.