Menu

Day 26 of My React Learning Journey πŸš€ | useEffect Hook and Component Lifecycle
πŸ“°

Day 26 of My React Learning Journey πŸš€ | useEffect Hook and Component Lifecycle

DEV Community: reactΒ·Saravanan CnΒ·13 days ago
#cv8Llg4x
#devtoreact#devto#dev#useeffect#component
Reading 0:00
15s threshold

I learned about the useEffect Hook in React and created an e-commerce website. I also learned about component lifecycle and dependency arrays.

1. What is useEffect?

useEffect is a React Hook that allows us to synchronize a component with external systems, such as APIs, timers, browser events, and other external resources.

It is commonly used to perform side effects in React components.

Syntax

`import { useEffect } from 'react';

useEffect(() => {

// Side effect code

}, [dependencies]);

`

2. Why do we use useEffect?

We use useEffect for tasks such as:

Fetching data from an API.

Setting up timers.

Adding event listeners.

Synchronizing with external systems.

Cleaning up resources when they are no longer needed.

3.…

Continue reading β€” create a free account

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