I know that when setting the state for a component that is not yet mounted, an error occurs. This explains the error I get from using the setState function, both against explicitly and directly setting the state.
import React, {Component} from 'react';
class SearchBar extends Component {
constructor(props) {
super(props);
this.state = {term: ''};
}
render() {
return (
<div>
<input onChange={event => this.setState({term: event.target.value})}/>
Value of the input: {this.state.term}
</div>
);
}
}
The error I get when I uncomment the second line of this.setState ({term: ''}):
Warning: setState (...): Can only upgrade mounted or mounted components. This usually means that you called setState () on an unmounted component. This is a no-op. Check the component code.
, , , React - , github, : Github Issue # 3878 , Cant React ? setState , , , ? , , , - , ?