Fork me on GitHub
#reagent
<
2022-09-20
>
jcb11:09:09

Hi, is there any difference in reagent between a ref and forwardRef? I'm struggling to find a direct reference in the docs

p-himik11:09:34

Reagent itself does not care about refs. Except when it's an <input> or a <textarea> because it wraps such a component internally to preserve the text cursor's state. But occasionally you might see some issues when interop'ing with React components when you use things like js->clj and clj->js because they convert refs as any other JS object. Which, of course, shouldn't be done - refs must stay the same object for them to work properly.

jcb11:09:35

Thank you. I'm just struggling to use a relatively simple react component from npm and am just working through the issues (it's been quite a while since I've used reagent or shadow-cljs). Do I need to name a forwardRef as such or would a ref be used normally?

p-himik11:09:59

Not sure what you mean by "naming a forward ref". But if you post some code and the errors that you see maybe I'll be able to tell what's wrong.

jcb11:09:14

sorry, I just mean, in the React code that I'm looking at a forwardRef is defined as such

jcb11:09:43

e.g const Page = React.forwardRef((props, ref) => etc etc

p-himik11:09:16

Right, you just require something like ["react" :as react] and then use (react/forwardRef (fn [props ref] ...)).

jcb12:09:42

Ah, grand. Thanks for your time!

👍 1