课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Component life-cycle and side effects
课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React
Component life-cycle and side effects
- [Instructor] Every React component has a life cycle. First it gets rendered by React in memory then React mount the component into the DOM, then the component might be updated again in the DOM and it can also be removed from the DOM. React provides method for us to execute code around these events in the life cycle of a component. We can for example, do something after the component is rendered or right before it gets re-rendered or unmounted. The simplest method to do that in React is with a useEffect function. Just like useState, useEffect is a function to define a side effect for the component. The use something functions in React are known as hooks. They were introduced a few years ago as an alternative to the other method that we used before them, which is to use React class components. And React still supports class components but using React hooks in function components is cleaner in my opinion, and I use it…