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()
Most helpful comment
@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:
You can then access
this.textInput.valueand call methods likethis.textInput.focus()