Each component has several “lifecycle methods” that you can override to run code at particular times in the process.
Methods prefixed with function should be pure, meaning that it does not modify component state, it returns the same result each time it’s invoked, and it does not directly interact with the browser.
a network request may not be necessary if the props have not changed).
If your component implements the is invoked immediately before a component is unmounted and destroyed.
This effectively “forks” the props and sets the state with the initial props.
Here’s an example of a valid Beware of this pattern, as state won’t be up-to-date with any props update.
Note that we don’t recommend creating your own base component classes.Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests, or cleaning up any subscriptions that were created in Error boundaries are React components that catch Java Script errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed.Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.Use this as an opportunity to perform preparation before an update occurs. Note that you cannot call is invoked right before the most recently rendered output is committed to e.g. It enables your component to capture current values (e.g.scroll position) before they are potentially changed.