Hacker News new | ask | show | jobs
by bringtheaction 3005 days 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?
1 comments

Yes, 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.