Fork me on GitHub
#reagent
<
2019-05-27
>
jcb16:05:38

Is it possible to use a react hook in reagent? A library has provided a helper hook but I can't figure out how to use it.

lilactown16:05:04

you cannot use it in a regular Reagent component

lilactown16:05:32

Reagent components get turned into React classes, which don’t have access to hooks

jcb16:05:18

ok, thanks

lilactown16:05:19

I think I remember an example @juhoteperi posted of creating a functional component using reagent as just a hiccup interpreter

lilactown16:05:24

you could try that

lilactown16:05:31

(defn MyComponent [props] ; <— props is a JS object
  (let [[count set-count] (react/useState 0)]
    (reagent.core/as-element [:div {:on-click #(set-count inc)} count])))

jcb18:05:41

Thanks, I don't understand though. Both my cljs and react are pretty basic. I'm trying to translate this - https://konvajs.org/docs/react/Images.html but I'm getting stuck in the js->cljs translation. I was hoping the hook would save me!

lilactown19:05:59

Reagent shines when you don’t need to do much interop with regular React components/hooks/libraries

lilactown19:05:25

if you’re interested, I created a library called #hx which serves that use case more. https://github.com/Lokeh/hx

👍 4
lilactown19:05:15

if you want to use libraries off of NPM and Hooks, you might have an easier time with hx