React #11 - Unmounting Phase - componentWillUnmount - Life Cylce Hooks in React
HTML-код
- Опубликовано: 9 окт 2024
- Click to watch React Playlist: • React
To view the code of this tutorial. Please visit this Github link:
github.com/let...
Life Cycle Hooks in React
Mounting Phase
constructor(): Called when the component is first created. It’s used to initialize state and bind methods.
componentDidMount(): Invoked immediately after a component is inserted into the DOM. It’s a good place to fetch data or set up subscriptions.
Updating Phase
shouldComponentUpdate(nextProps, nextState): Determines if a component should re-render based on changes in props or state.
componentDidUpdate(prevProps, prevState): Called immediately after updating occurs. It’s useful for performing DOM operations or network requests based on the previous state or props.
Unmounting Phase
componentWillUnmount(): Invoked just before a component is removed from the DOM. It’s used for cleanup tasks like invalidating timers or canceling network requests.
Error Handling
componentDidCatch(error, info): Called when an error is thrown during rendering, in a lifecycle method, or in the constructor of any child component. It allows you to handle errors gracefully.