I tried just now, setting this.myRef = []; and using callbacks ref={(ref) => { this.myRef[someval] = ref; return true; }} - everything worked perfectly.
Iām a Software Developer with hands-on experience building scalable mobile and web applications, streamlining workflows with automation, and experimenting with AI-driven solutions for business impact.
Location
Pune, India
Education
B-Tech in Computer Science and. Technology engineering
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 ?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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) }}>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!!
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 ?