3 ms·
Can someone explain to me why they went for static getDerivedStateFromProps(nextProps, prevState) Instead of getDerivedStateFromProps(nextProps) Was
by bringtheaction 9y ago
Can someone explain to me why they went for
static getDerivedStateFromProps(nextProps, prevState)
Instead of
getDerivedStateFromProps(nextProps)
Was it to prevent people from mutating the object perhaps?
- danabramov 9y agoYes, since that’s the most common issue with what people do in componentWillReceiveProps. It is invoked during the interruptible phase in async mode so mutations and side effects are unsafe there. Same as in the render method.