https://faroukibrahim-fii.github.io/reading-notes/
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.
When an instance of a component is being created and inserted into the DOM it occurs during the mounting phase
Anytime a component is updated or state changes then it is rerendered.
The final phase of the lifecycle if called when a component is being removed from the DOM.
The constructor for a React component is called before it is mounted.If the component is a subclass you should call super(props), or the props will be undefined.
This method exists for rare cases where the state relies on changes in props over time.
Render is the only required method in a class component. It will examine this.props and this.state when called.
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.
The default behavior in react is to rerender after every state change. Setting shouldComponentUpdate() to false allows you to prevent this from happening.
This is another rarely used method that allows you to capture a picture of the DOM to check it before actually changing anything on the DOM.
This method is useful for performing network requests after a change has occurred.
This method allows you to clean up the DOM and netwrok requests/ subscriptions.
UNSAFE_componentWillMount() UNSAFE_componentWillUpdate() UNSAFE_componentWillReceiveProps()
These events have lead to a lot of bugs and unintended side effects, so in React 17 these will no longer be able to be used without the UNSAFE tag in front of them. Instead of componentWillMount use ComponentDidMount.
Instead of componentWillReceiveProps use static getDerivedStateFromProps. Instead of componentWillUpdate us getSnapshotBeforeUpdate.