https://github.com/fitzmode/use-dynamic-refs
A React hook to dynamically set and get Refs.
https://github.com/fitzmode/use-dynamic-refs
react react-hook react-hooks reactjs refs
Last synced: 5 months ago
JSON representation
A React hook to dynamically set and get Refs.
- Host: GitHub
- URL: https://github.com/fitzmode/use-dynamic-refs
- Owner: fitzmode
- Created: 2020-04-13T20:39:01.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-23T02:20:28.000Z (almost 2 years ago)
- Last Synced: 2025-08-23T01:52:01.481Z (5 months ago)
- Topics: react, react-hook, react-hooks, reactjs, refs
- Language: HTML
- Homepage:
- Size: 600 KB
- Stars: 59
- Watchers: 3
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React use-dynamic-refs
> Made with create-react-library
[](https://www.npmjs.com/package/use-dynamic-refs) [](https://standardjs.com)
## Install
```bash
npm install --save use-dynamic-refs
```
## Usage
```tsx
import React, { useEffect } from 'react';
import useDynamicRefs from 'use-dynamic-refs';
const Example = () => {
const foo = ['random_id_1', 'random_id_2'];
const [getRef, setRef] = useDynamicRefs();
useEffect(() => {
// Get ref for specific ID
const id1 = getRef('random_id_1');
console.log(id1)
}, [])
return (
<>
{/* Simple set ref. */}
{/* Set refs dynamically in Array.map() */}
{ foo.map((eachId, idx) => (
Hello {each} ))}
>
)
}
export default Example;
```
## License
MIT © [fitzmode](https://github.com/fitzmode)