I am trying to migrate my apps to do the React v16.3.* API, and it has been quite difficult to get rid of componentWillReceiveProps
. I have components which are dependent on it and call the components other function in them.
Because getDerivedStateFromProps
is static, I can't easily do this anymore and I need help on how to appropriately. For this case in particular, I have a timeout function that resets whenever new props are received. It currently is as follows:
componentWillReceiveProps (nextProps) {
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
this.dismiss(null, nextProps)
}, nextProps.timer)
}
As you can see I have this.timeout
and this.dismiss
which I cannot access anymore once the change is made to getDerivedStateFromProps
. How to I deal with this? Is there a way to change this to be a getDerivedStateFromProps
static function or do I have to go about this a completely different way?