Fork me on GitHub
#reagent
<
2021-11-21
>
Max17:11:16

Hi all! I’m working with a library with an unavoidably-imperative API (https://github.com/0xfe/vexflow/wiki/Tutorial for those interested). So far, my approach to functionalizing it is to pass a data structure describing what I want rendered to a react component. With vanilla react I’d use a combination of refs and useEffect to imperatively render the data. Refs are straightforward enough with reagent, but I’m not sure what the equivalent of useEffect is. Is there an easy way to run some code after every render without going all the way into a form-3 component? Or should I switch to a functional component?

🎶 1
lilactown19:11:43

you should use a form 3 component or a functional component

WonderLastking22:11:41

Hi there, I want to handle some key events, so I have found the following lib https://github.com/gadfly361/re-pressed But, while I have called both

(re-frame/dispatch-sync [::rp/add-keyboard-event-listener "keydown"]) 

(re-frame/dispatch
     [::rp/set-keydown-rules
        {:event-keys [[[::key-events/spacebar-pressed]
                     [{:keyCode 32}]]}])
My event ::key-events/spacebar-pressed is never called. I can see from the re-frame-10x that in the event-history tab the :re-pressed.core/set-keydown-rules event is called, but no luck when I press the spacebar Any thoughts? Maybe my question is fit better to the re-frame channel, but on lib's GitHub page, author @gadfly361 says for any questions he can be found at reagent channel

Schpaa23:11:18

Make sure your browser doesn't consume the keys (via plugins etc). This bites me all the time

Bobby Towers01:11:32

The spacebar has a default function in the browser that needs to be overridden. Re-pressed has a special way of handling these: https://github.com/porkostomus/typing/blob/9bf7f3f5be4aa867593a70b5287d5f29e97a95d2/src/typing/views.cljs#L77

👍 1
gadfly36101:11:37

It has been a while for me, but if the browser is swallowing the key then I would try @U8LB00QMD suggestion 👍

WonderLastking07:11:04

Hmm ok guys thanks you, will try the prevent-default-keys and let you know 🙂

WonderLastking22:11:30

I'm a little bit late, but.. It worked! Thank you guys!

👍 2