forlooptanzania / ride-my-way

Car pooling app (of developers) by developers for developers in Tanzania
22 stars 6 forks source link

What is the React Component Lifecycle like? #6

Open noelnoja opened 5 years ago

noelnoja commented 5 years ago

In React, the component(s) always follow a cycle from the time of creation, when it is mounted on the DOM up to when it is unmounted and destroyed.

React provides hooks(methods) which are naturally called at each point in the lifecycle, these methods give us good control of what happens at the point it is invoked.

So simply a react hook is a method which is called automatically when a component is either rendered in the DOM, Updating the DOM or unmounting itself from the DOM. A good example of React lifecycle hook is componentDidMount, this method will be triggered when a Component's output is first inserted into DOM.