Answer the question
In order to leave comments, you need to log in
ReactJS error - "This synthetic event is reused for performance reasons", what to do?
Greetings!
I am studying React according to the documentation, I reached the section with forms and there was a misunderstanding: if you save the field value like this: - everything works. But, going back to the State and Life Cycle section , we see that it is recommended to update `state` like this:this.setState({value: e.target.value})
e.persist();
this.setState(state => ({
value: e.target.value
}));
e.persist()
. Called, everything worked. class App extends React.Component {
constructor() {
super();
this.state = {value: 'Hello, world!'}
}
formUpdate = (e) => {
// вариант 1
this.setState({value: e.target.value});
// вариант 2
e.persist();
this.setState(state => ({
value: e.target.value
}));
}
render() {
return (
<div>
<h1>{this.state.value}</h1>
<form>
<label>Новое название:
<input type="text" value={this.state.value} onChange={this.formUpdate}/>
</label>
<button type="submit">Изменить</button>
</form>
</div>
);
}
}
ReactDOM.render(<App/>, document.getElementById("root"));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question