How To Get Input Value Of Textfield From Material Ui?
So, before using material UI, my code was like this. To implement edit feature for ToDo app I used ref from textarea for get current (default) value in there, and then save updated
Solution 1:
Add a simple event handler when the user enters text, you can then use a callback to move the input from the text field to whatever component you want, here's the full example
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';
const styles = theme => ({
container: {
display: 'flex',
flexWrap: 'wrap'
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: '61px'
}
});
class OutlinedTextFields extends React.Component {
handleOnChange = event => {
console.log('Click');
console.log(event.target.value);
};
render() {
const { classes } = this.props;
return (
<form className={classes.container} noValidate autoComplete="off">
<TextField
id="outlined-editToDO"
label="Edit ToDo"
defaultValue={this.props.defaultToDoValue}
className={classes.textField}
multiline
margin="normal"
variant="outlined"
onChange={this.handleOnChange}
/>
</form>
);
}
}
OutlinedTextFields.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(OutlinedTextFields);
Post a Comment for "How To Get Input Value Of Textfield From Material Ui?"