I tried just now, setting this.myRef = []; and using callbacks ref={(ref) => { this.myRef[someval] = ref; return true; }} - everything worked perfectly.
hello, how can i access stored values in myRef, like say what if i want to access next myRef value on currnet myRef, what should i do there? myRef.nextItem ?
I tried just now, setting
this.myRef = [];
and using callbacksref={(ref) => { this.myRef[someval] = ref; return true; }}
- everything worked perfectly.Thanks, this was helpful. If anyone else out there wants to do this with TypeScript and hooks, this worked like a charm for me:
const tentRefs = useRef<(HTMLDivElement | null)[]>([])
<div className="name-tent" key={studentId} ref={(ref) => { tentRefs.current.push(ref) }}>
hello, how can i access stored values in myRef, like say what if i want to access next myRef value on currnet myRef, what should i do there? myRef.nextItem ?
It worked for me as well. This is really cool. I have never used ref in loop and was facing issues, but with your help it rocked. Thanks!!