Skip to content

Latest commit

 

History

History
22 lines (12 loc) · 1.31 KB

File metadata and controls

22 lines (12 loc) · 1.31 KB

What are component lifecycle events?

React lets you define components as classes or functions. The methods that you are able to use on these are called lifecycle events. These methods can be called during the lifecycle of a component, and they allow you to update the UI and application states.

Based off the diagram, what happens first, the ‘render’ or the ‘componentDidMount’?

render

What is the very first thing to happen in the lifecycle of React?

Mounting

Put the following things in the order that they happen: componentDidMount, render, constructor, componentWillUnmount, React Updates

Constructor, static getDerivedStateFromProps, render, componentDidMount, and UNSAFE_componentWillMount all occur in this order during mounting.

What does componentDidMount do?

This method is invoked immediately after a component is mounted. If you need to load anything using a network request or initialize the DOM, it should go here. This method is a good place to set up any subscriptions. If you do that, don’t forget to unsubscribe in componentWillUnmount(). setState() can be called here, but it should be used sparingly, because it will cause a rerender, which can lead to perfomance issues. Here we use componentDidMount() to connect to the YouTube API and get videos when the components is rendered.