This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-05
Channels
- # announcements (7)
- # babashka (20)
- # beginners (130)
- # bristol-clojurians (1)
- # cider (14)
- # clj-kondo (7)
- # cljdoc (14)
- # cljs-dev (15)
- # cljsrn (16)
- # clojars (11)
- # clojure (190)
- # clojure-dev (4)
- # clojure-europe (7)
- # clojure-italy (9)
- # clojure-nl (3)
- # clojure-romania (6)
- # clojure-uk (51)
- # clojurescript (44)
- # component (4)
- # conjure (28)
- # cursive (1)
- # data-science (4)
- # datascript (1)
- # datomic (30)
- # duct (4)
- # emacs (1)
- # figwheel (4)
- # fulcro (56)
- # graalvm (4)
- # helix (51)
- # jackdaw (2)
- # jobs-discuss (12)
- # joker (4)
- # lambdaisland (1)
- # local-first-clojure (1)
- # meander (73)
- # mid-cities-meetup (2)
- # nrepl (4)
- # off-topic (43)
- # pathom (56)
- # re-frame (37)
- # reagent (26)
- # shadow-cljs (161)
- # slack-help (9)
- # spacemacs (1)
- # tools-deps (18)
- # xtdb (18)
ah I found some old code I wrote where I had made this hook:
(defn useChan [chan on-take on-close]
(hooks/use-effect
[chan on-take on-close]
(let [cleanup? (a/chan)]
(a/go-loop []
(let [[v ch] (a/alts! [chan cleanup?])]
(cond
(= ch cleanup?) (on-close)
(nil? v) (on-close)
:else (do (on-take v)
(recur)))))
#(do (a/put! cleanup? true))))))
Why do we need the 2nd element of the use-effect to be [chan on-take on-close]
?
if the chan
on-take
or on-close
values change, we want to restart the go-loop with the new values. that vector is of any dependencies that should cause the effect to re-run
not a defhook macro at least : D I am guessing that's why the go-loop recur is complaining
I was getting a lot of help from people, and tried out always the easiest. Will check the useChan right now
and from all the responses together I get the feeling that the problem is somewhere else
Howdy, How can I do if I want add on-click event to style-components
(defstyled StyleNumberButton
:div
{:display "flex"
:color "white"
:border "1px solid black"
:border-radius "10px"
:background "gray"
:height "100px"
:width "50px"})
@lilactown any idea?
No ... you just can pass an component
I guessed that too, but that doesn't work ... I was wondering if is possible helix give this returned element the possibility to add this events
if that doesn’t work, it’s a bug with styled components and you should file a report
I will try, thank you
WORKS WITH :onClick !!! thank you master
@lilactown definitely something else, because not even this example works https://clojurians.slack.com/archives/C053AK3F9/p1588644858480300 basically, any time I used recur it said it cannot do it
if you’re ever curious about what $
is doing you can use macroexpand:
(macroexpand '($ foo {:bar "baz"}))
;; => (. (helix.core/get-react) createElement foo (helix.impl.props/props {:bar "baz"}))
if you macroexpand the helix.impl.props/props
call you can see exactly how it creates the JS object:
(macroexpand '(helix.impl.props/props {:bar "baz"}))
;; => (let* [obj85058 (js* "({~{}:~{}})" "bar" "baz")] obj85058)
@lilactown (mapv #($ ListFile {& %}) files)
? 🙂
yeah you should be able to pass a seq of elements to any other element, but you probably need to add a :key
prop to help React
@lilactown but I can't create the seq of elements like that
Ok, I think I got it working. In retrospect, it's probably me being very inept with clojure what's causing most of my problems.
If I want to pass a non-literal map to a component as props, is using a factory the best option? Eg ((helix/factory my-component) my-map)
?
@tomc https://github.com/Lokeh/helix/blob/master/docs/creating-elements.md#dynamic-props
Thanks. So if I have my-map as a local, do I need something like ($ component {& my-map})
?
Thanks again. Maybe the docs should mention this variant of dynamic props. It wasn't immediately obvious that this was the preferred solution, though it makes sense now that I know it.
That part was clear. What wasn't clear to me was that this is the preferred way to pass props to a subcomponent when all you have is a local binding, since we also have the option to use factories, and the factory approach seems to produce the same result.
factories vs $
is sort of a separate issue. they both solve the same problem, it’s a question of syntax
I think I know a decent addition, I'll get you the pr in a few minutes. thanks for the help.
@lilactown If you're open to it, I'd be happy to also write a quick "integration with reagent" guide to help people with my use case - a primarily reagent+re-frame project with bits of helix added to make integration with js react libs easier