Last remaining componentWillReceiveProps, whew

This commit is contained in:
James Barnsley
2020-03-12 21:32:50 +13:00
parent 29b7b65b9c
commit 28fc55bad1
18 changed files with 6810 additions and 10005 deletions

View File

@ -14,11 +14,15 @@ class SearchForm extends React.Component {
};
}
componentWillReceiveProps = (nextProps) => {
const { pristine, term } = this.state;
if (pristine && term === '' && term !== nextProps.term) {
this.setState({ term: nextProps.term, pristine: false });
static getDerivedStateFromProps(props, state) {
const { pristine, term } = state;
if (pristine && term === '' && term !== props.term) {
return {
term,
pristine: false,
};
}
return null;
}
shouldComponentUpdate = (nextProps, nextState) => {
@ -73,7 +77,6 @@ class SearchForm extends React.Component {
}
render() {
console.log('rendering', this.state);
return (
<form className="search-form" onSubmit={(e) => this.handleSubmit(e)}>
<label>