Answer the question
In order to leave comments, you need to log in
Implementation of this.state?
class AddInfo extends Component{
state={
value:""
}
render() {
const {classes}=this.props
const newStyles=injectSheet(styles)(AddInfo)
const val=this.state.value
return (
<div>
<input type="text" className={classes.positionForm} onChange={this.changeState} />
<input type="submit" value="value" />
{val}
</div>
);
}
changeState=(event)=>{
this.setState({
value:event.target.value
})
}
}
Answer the question
In order to leave comments, you need to log in
The state should have two properties - the value of the input and its copy. In the input's onChange handler, update the value of the input; in the onClick handlers of the button and onMouseLeave of the form, copy the value of the input to the second property, and reset it itself.
Or you can try to get by with one property in the state, but then you need to add a ref to the input. There is no need to process change in this case.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question