DEV Community

Discussion on: My collection of React Interview questions (Part 1)

Collapse
 
themindfuldev profile image
Tiago Romero Garcia • Edited

Excellent list, great job @migueloop !

Just to mention something that recently changed: in React 16.3.0, some lifecycle methods have been deprecated:

  • componentWillMount()
  • componentWillReceiveProps()
  • componentWillUpdate()

They still can be used for now, but you would need to prefix it with UNSAFE_, like UNSAFE_componentWillMount, UNSAFE_componentWillReceiveProps, and UNSAFE_componentWillUpdate.

These are expected to be removed on React 17.

We got then some new methods to compensate for that:

  • getDerivedStateFromProps(props, state) - Called after a component is instantiated as well as before it is re-rendered. It can return an object to update state, or null to indicate that the new props do not require any state updates.
  • getSnapshotBeforeUpdate(prevProps, prevState) - Called right before mutations are made (e.g. before the DOM is updated). The return value for this lifecycle will be passed as the third parameter to componentDidUpdate. (This lifecycle isn’t often needed, but can be useful in cases like manually preserving scroll position during rerenders.)

Source (with examples): Update on Async Rendering.

Collapse
 
migueloop profile image
Miguel Ruiz

That's true Tiago. When I first did my list we had an older version of React. I will update it asap. Thanks so much

Collapse
 
themindfuldev profile image
Tiago Romero Garcia

You are welcome, Miguel!

And totally, these things change so fast these days!

Thread Thread
 
migueloop profile image
Miguel Ruiz

Updated Tiago! Thanks a lot