I need to update a child's state when a prop gets updated, so I made something like this:
componentDidUpdate(prevProps) {
const { searchValue, searchCriterion } = this.props;
if (searchValue !== prevProps.searchValue) {
this.setState({ searchValue });
}
if (searchCriterion !== prevProps.searchCriterion) {
this.setState({ searchCriterion });
}
}
ESLint's airbnb guide is complaining about it and throwing this warning, even though I can't see any noticeable rendering or performance issues.
The warning says:
Updating the state after a component update will trigger a second render() call and can lead to property/layout thrashing.
Is there a better way to update a child's state when a prop has a new value?
Or should I ignore the warning?