[Suggestion]: Documentation for useRef
should tell us how to deal with multiple refs on a single element
#7251
Labels
useRef
should tell us how to deal with multiple refs on a single element
#7251
Summary
Sometimes you need to add more than one ref to a single element. For example:
forwardRef
you need to pass the forwarded ref to whatever element, but you also need your own ref attached to the same element.useController
ofreact-hook-form
, you get a ref you need to pass to the input element for focus management, but you also need your own ref for doing other things with that same input element.This is an issue that is not even mentioned on the current documentation of
useRef
. I've been using gregberge/react-merge-refs to deal with this, but after I added the recommendedeslint-plugin-react-compiler
, this method now generates a warning:If you're not allowed to access ref values during render to merge them, then how are you supposed to attach multiple refs to a single element now?
The documentation needs to tell us how to do this properly, and in a way that doesn't break the compiler or generate warnings in your eslint plugins.
Page
https://react.dev/reference/react/useRef
Details
Example component needing this:
The text was updated successfully, but these errors were encountered: