Fluentui: How to use componentRef instead of ref attribute

Created on 21 Aug 2017  ·  1Comment  ·  Source: microsoft/fluentui

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!

Question ❔

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:

<TextField componentRef={(input) => this.textInput = input }/>

You can then access this.textInput.value and call methods like this.textInput.focus()

>All comments

@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()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prashkan picture prashkan  ·  3Comments

carruthe picture carruthe  ·  3Comments

nekoya picture nekoya  ·  3Comments

justinwilaby picture justinwilaby  ·  3Comments

carruthe picture carruthe  ·  3Comments