I'm trying to access input data using React's "ref" attribute on a TextField in Material-UI. There doesn't seem to be an easy way of doing this via the 'inputRef' or 'inputProps'.
The below sample shows the use of inputProps on line 26. Assigning the name of the TextField to the 'ref' property does not appear to produce a valid object.
With the “inputRef”, which according the Material-ui docs forces the use of a function, attempting to pass the field data in as an attribute also doesn't work. Ex: (txt => this.name = txt)
Has anyone found a solution?
class MediaForm extends Component { constructor (props) { super(props) this.state = {} this.handleSubmit = this.handleSubmit.bind(this) } handleSubmit (e) { const { title, colour } = this.refs e.preventDefault() window.alert(`New colour: ${title.value} ${colour.value}`) } render () { const { classes } = this.props return ( <form className={classes.root} onSubmit={this.handleSubmit}> <div className={classes.field}> <TextField name='title' type='text' label='Title' placeholder='Movie title...' autoFocus inputProps={{ref: this.name}} required /> </div> <div className={classes.field}> <Tooltip title='Add a colour the reflects the mood of the film'> <TextField name='colour' type='color' label='Mood' inputProps={{ref: this.name}} required /> </Tooltip> </div> <Button variant='raised' color='primary' className={classes.button}> ADD </Button> </form> ) } } MediaForm.propTypes = { classes: PropTypes.object.isRequired } export default withRoot(withStyles(styles)(MediaForm))