Dynamically generate and reference React ref instances with this handy hook.
npm install use-ref-map


Dynamically generate and reference React reference instances with this handy hook.
Via npm
``sh`
npm install use-ref-map
Via Yarn
`sh`
yarn add use-ref-map
`
import useRefMap from 'use-ref-map
const ExampleComponent = ({ buttonData }) => {
const { getRef, setRef } = useRefMap()
const handleSubmit = (evt) => {
evt.preventDefault()
const email = getRef('email_input')?.current?.value
const password = getRef('password_input')?.current?.value
}
return (
_This is a silly example, but should give you an idea of how to use this hook. This is most useful when dealing with an array of components that require unique ref instance props passed to each, using an example key of something like, dynamic-ref-${id}`._