Fork me on GitHub
#helix
<
2021-05-19
>
Lucy Wang01:05:38

@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.

dominicm15:05:20

Sure 馃檪 Clojure does this automatically under the hood for you with gen-class, to allow you to do this without doing it manually!

dominicm15:05:34

It would be cool if the new shadow classes also did that.

位mmij09:05:15

Hi everyone.

位mmij09:05:13

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]))

Aron10:05:07

but I am not sure I get your full meaning, what is 'not define'?

位mmij10:05:56

i cant use the defnc. 

位mmij10:05:16

(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))}))))

位mmij10:05:58

It was refer from the helix.core namespace but defnc doesnt exist there.

位mmij10:05:44

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.

jimmy12:05:12

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?

位mmij13:05:12

I seems that I just fix itself after I restart build. I doesn't throw an error only warning.

位mmij13:05:26

I made to work now thanks.

位mmij14:05:55

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

jimmy15:05:58

What editor are you using? That is the behavior of your editor.

lilactown16:05:56

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?

lilactown16:05:33

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

位mmij23:05:20

Im using vscode. But the program works though. I got the display on localhost correctly. Sorry for bothering. I am just programming for fun.

位mmij00:05:18

I will just go back using reagent at the moment.

jimmy12:05:32

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 :)

lilactown16:05:38

I think it does work but only accidentally

Aron17:05:29

sounds promising