7.0: Lifecycle Overview
Last updated
Last updated
Think about the circle of life (cue lion king music) for living creatures, and then imagine your React components as little beings going through the same process. They're brought into the world of your app, they go through some changes, and then they eventually die off. This is how React components work, and the React team has provided a series of methods you can use to tap into this process.
The first phase of the React Component life cycle is the birth of a component, or as it's called in React terminology, the mounting of the component. Mounting is where the component starts initializing, and the Component's props and state are defined and configured. The Component and all its children are mounted onto the Native UI Stack (DOM, UIView, etc.).
The mounting phase only occurs once.
The next phase of the life cycle is the Growth/Update phase. This is the phase where the majority of all the action happens, the majority of time is spent, and this phase can, and usually does, repeat many times. This is where users are interacting with the app and the component is changing things in response to those actions. Some things that can happen are changing state, new props, handling user interactions and input, and communicating with other components.
The last phase of the React Component life cycle is the Death/Unmount phase. This phase can occur when the user navigates away, the UI page changes, a component is hidden, etc. This is called unmounting in React terms.
Unmounting occurs only once and readies the Component for Garbage Collection.