Created
August 11, 2020 12:20
-
-
Save palanisamym14/6e41de2b7604fc91cc99664d9fdaa1d9 to your computer and use it in GitHub Desktop.
This file contains 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 App = props => { | |
const itemsRef = useRef([]); | |
// you can access the elements with itemsRef.current[n] | |
useEffect(() => { | |
itemsRef.current = itemsRef.current.slice(0, props.items.length); | |
}, [props.items]); | |
return props.items.map((item, i) => ( | |
<div | |
key={i} | |
ref={el => itemsRef.current[i] = el} | |
style={{ width: `${(i + 1) * 100}px` }}> | |
... | |
</div> | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment