Skip to content

dom-node deprecation #599

Closed Answered by Deraen
hkjels asked this question in Q&A
Discussion options

You must be logged in to vote

React refs are the answer in React to access DOM nodes, and are much for versatile than getting the component top node: https://react.dev/reference/react/useRef

Unfortunately Reagent docs are pretty out of date regarding refs. React Features doc should probably include a section.

You can use the hook with functional components, or create a form-2 component with local state atom for el reference and a ref fn.

(let [ref (atom nil)
      ref-fn #(reset! ref %)]
  (fn []
     [:div {:ref ref-fn} ...]))

It is usually also good to create the ref-fn in the fn closure to ensure the fn value doesn't change on every render.
Storing the el reference in a ratom is potentially problematic, if you als…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hkjels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants