Menu

React.js ~Life Cycle~
🖼️

React.js ~Life Cycle~

DEV Community·Ogasawara Kakeru·6 months ago
#jCAYAV2U
#development#webdev#react#learning#useeffect
Reading 0:00
15s threshold

In React, the life cycle is composed of Mount(create) , Update(update) and Unmount(delete) .

The life cycle method is defined as those of method.

componentDidMount

created when the first render once.

Used when API connection, DOM manipulation.

componentDidUpdate

Run when updating DOM.

Used in every time updating such as DOM manipulation.

componentWillUnmount

Run when deleting components.

Used in eventListner, timer, and closing API connection.

Side Effect Hook

useEffect hook can replace the life cycle method instead.

useEffect can be used for componentDidMount(runs when generate component) , componentDidUpdate(runs every time update) and componentWillUnmount(runs when delete component) .

**componentDidMount

useEffect ( () => { // Runs when initial render }, []);

Enter fullscreen mode

Exit fullscreen mode

**componentDidUpdate

useEffect ( () => { // Runs every time when rendering });

Enter fullscreen mode

Exit fullscreen mode

**componentWillUnmount

useEffect ( () => { // Runs every time…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.