Last active
June 23, 2021 13:40
-
-
Save supahfunk/3a7b90989a7107222143a1621bcc8dda to your computer and use it in GitHub Desktop.
React useRef in map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyComponent = ({ items }) => { | |
const $items = useRef(items.map(createRef)) | |
useEffect(() => { | |
console.log($items.current[0].current) | |
}, []) | |
return ( | |
{items.map((item, index) => ( | |
<div | |
key={index.toString()} | |
ref={$items.current[index]} | |
> | |
{item.name} | |
</div> | |
))} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment