How to use componentRef instead of ref attribute
Describe the issue:
I want to understand how to use componentRef attribute instead of ref attribute.
Let's say i have <TextField ref='mytf' /> . From my code i can get the value of the textfield like this - (this.refs['mytf'] as TextField).value, now as componentRef is a callback, i can't really understand how to use it for getting the value of the textfield. Can you please provide an example?
Thanks!
@artxach React documentation has good information on this. String refs are legacy and the callback pattern should be used instead. https://facebook.github.io/react/docs/refs-and-the-dom.html
For example:
<TextField componentRef={(input) => this.textInput = input }/>
You can then access this.textInput.value and call methods like this.textInput.focus()