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))))))
thanks, that's very nice
not a defhook macro at least : D I am guessing that's why the go-loop recur is complaining
does go-loop
and recur
not work when used inside defhook
?
I am probably doing something wrong, it's a bit late at night, I need a coffee : )
I was getting a lot of help from people, and tried out always the easiest. Will check the useChan right now
in #beginners
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?
I’m not familiar with styled-components, sorry
I would assume you can pass in an on-click handler to it when you invoke it?
No ... you just can pass an component
I don’t know what you mean
I’m guessing you can do (StyleNumberButton {:on-click ,,,})
or something?
again, I do not know how this CLJS styled-components library works
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
I don’t see how helix comes into this?
if that doesn’t work, it’s a bug with styled components and you should file a report
you could try :onClick
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
but (go (loop
instead of go-loop
seems to work. Dunno why I haven't tried this first?
I am not sure the ($ macro is helping me with the props thing
happy to help if you explain the problem 🙂
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)
? 🙂
(apply <> (mapv
I think, but inside the mapv?
well, it works without the apply I think, haven't read the source
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
is there maybe a branch or something with an easy sandbox to demonstrate
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})
?
yep
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.
Do you mean that the docs I linked are not clear that you can use a local binding?
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’ve written almost no docs on factory functions
we don’t use them on our project at work
I would accept a PR to clarify the docs, I’m just not sure how to be clearer yet 😄
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
that would be awesome and super useful to people I bet!