Part 40 React Tutorial | React Life cycle methods | Mounting | смотреть онлайн
Lifecycle of Components
Each component in React has a lifecycle that you can monitor and manipulate during its three main phases.
Below phases are available:
1. Mounting phase
2. Updating phase
3. Unmounting phase
4. Error handling phase
1. Mounting:-
------------
- Mounting means putting elements into the DOM.
1. constructor(props)
- Whenever object is created, constructor will be executed.
- This is the first method called during the creation of a component instance.
- It is best places to do the initalization, setup the state variables.
2. static getDerivedStateFromProps(props, state)
- This method is called before the initial render of a component, and any time new props are passed to the component.
- It is used to update the component's state based on the props that were passed.
3. render()
- This method is required for all React components. It is used to generate the HTML markup for the component based on its current props and state.
4. componentDidMount()
- This method is called after the initial render of a component. It is used to perform any tasks that require access to the DOM, such as setting up event listeners or fetching data from a server.
2. Updating phase:-
----------
- A component is updated whenever there is a change in the component's state or props.
1. static getDerivedStateFromProps(nextProps, prevState)
- Also at updates this method is called. This is the first method that is called when a component gets updated.
- This method is called when new props are received by the component. It is used to update the component's state based on the new props.
2. shouldComponentUpdate(nextProps, nextState)
- Returns a Boolean value that specifies whether React should continue with the rendering or not.
- if it returns false then component will not be updated. Default value is true.
- This method is called before a component is updated. It is used to determine whether the component should re-render or not, based on changes to its props or state.
3. render()
- It is called when a component gets updated, it has to re-render the HTML to the DOM, with the new changes.
4. getSnapshotBeforeUpdate()
- This method provides the previous state and property value.
- If the getSnapshotBeforeUpdate() method is present, you should also include the componentDidUpdate() method, otherwise you will get an error.
5. componentDidUpdate(prevProps, prevState)
- This method is called after the component is updated in the DOM.
- It is used to perform any tasks that require access to the DOM or the component's state or props, such as updating a chart or triggering an animation.
3. Unmounting:-
-----------
- When a component is removed from the DOM, or unmounting as React likes to call componentWillUnmount().
1. componentWillUnmount()
- The componentWillUnmount method is called when the component is about to be removed from the DOM.
- It is used to clean up any resources that the component has acquired, such as event listeners or timers.
4. Error handling phase:-
--------------------
1. static getDerivedStateFromError(error):-
- This method is called when a child component throws an error. It is used to update the state of the parent component based on the error.
2. componentDidCatch(error, info):-
- This method is called after a child component throws an error. It is used to log the error or display an error message to the user.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Part 40 React Tutorial | React Life cycle methods | Mounting |» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.