Answer the question
In order to leave comments, you need to log in
How to replace componentWillReceiveProps?
I'm getting a warning in the browser console
Warning: componentWillReceiveProps has been renamed, and is not recommended for use.
Please explain how to fix it on getDerivedStateFromProps
If possible clearly, in other cases I think I'll figure it out myself! Thanks
My component
constructor(props) {
super(props)
this.state = {
query: '',
toggle: 'off'
}
}
componentWillReceiveProps(nextProps) {
if (!nextProps.location.pathname.includes('/search')) {
this.setState({
query: '',
toggle: 'off'
})
}
}
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