Exambodh - Practice Aptitude, Reasoning & GK Questions
Play Quiz
Start practice
≡One Liner Questions⌂Home?Play QuizAaArticles
General Knowledge›
Indian History›
Indian Polity›
Quantitative Aptitude›
Logical Reasoning›
Interview Practice›
General Science›
Computer Awareness›
View more categories (4)
Current Affairs›
Geography›
NCERT Solutions & Notes›
Static GK›
  1. Home
  2. |Articles
  3. |React useState and useEffect Hooks – Explanation with Examples
←Back to Articles
ReactjsUseEffect and UseState

React useState and useEffect Hooks – Explanation with Examples

Reactjs15 March 20265 min read

Share Article

Share on social media or copy your public link.

FacebookWhatsAppLinkedIn

React.js

React useState and useEffect Hooks – Explanation with Examples

React Hooks make functional components more powerful and easier to manage. Among all hooks, useState and useEffect are the most commonly used. In this article, you will learn why they are used, how they work, and where to use them with simple examples.

Quick Summary

  • useState is used to store and update data inside a component.
  • useEffect is used to run side effects such as API calls, timers, and DOM updates.
  • Both hooks are essential for building dynamic React applications.

What is useState in React?

The useState hook is used to manage state inside a functional component. State means data that can change over time.

Why use useState?

  • To store dynamic values inside a component
  • To update UI automatically when values change
  • To manage counters, forms, and toggles
  • To make functional components interactive

Syntax of useState

const [state, setState] = useState(initialValue);

state → Current value

setState → Function used to update value

initialValue → Default starting value

Example of useState

Below example shows a simple counter using useState.

import React, { useState } from "react";

function Counter() {

const [count, setCount] = useState(0);

return (
  <div>
    <h2>Counter: {count}</h2>
    <button onClick={() => setCount(count + 1)}>
      Increase
    </button>
  </div>
);

}

export default Counter;

Explanation

Here count stores the current value and setCount updates it. When the button is clicked, React re-renders the component.

What is useEffect in React?

The useEffect hook is used to perform side effects in a component.

Why use useEffect?

  • Fetching API data
  • Running code on component load
  • Managing timers and intervals
  • Updating DOM

Syntax of useEffect

useEffect(() => {

 // side effect code

}, [dependency]);

[] → Runs once when component loads

[value] → Runs when value changes

No dependency → Runs after every render

Conclusion

Both useState and useEffect are essential React hooks. useState manages data, while useEffect handles side effects like API calls.

Frequently Asked Questions

Why use useState in React?

It stores and updates dynamic data inside components.

Why use useEffect?

To perform side effects such as API calls and timers.

Can both hooks be used together?

Yes, usually useEffect fetches data and useState stores it.

More In Reactjs

Read more articles from the same category or open the full category archive directly.

Debounced Search Input

React js

How to Build a Debounced Search Input in React.js

“A fast UI is not about making more API calls — it’s about making smarter API calls.”

React js

React js

React 19 Features Explained with React 18 vs React 19 Comparison

“React 19 is not just a version update — it changes how developers handle forms, async UI, optimistic updates, and rendering performance in modern React applications.”

Javascript

React js

React Interview Questions and Answers 2026 | SSR, CSR, Hooks, Virtual DOM

“React becomes powerful when you understand how rendering, state updates, hooks, and performance optimization work together behind the scenes.”

React js
Debounced Search Input

How to Build a Debounced Search Input in React.js

React js
React js

React 19 Features Explained with React 18 vs React 19 Comparison

React js
Javascript

React Interview Questions and Answers 2026 | SSR, CSR, Hooks, Virtual DOM

View All Reactjs Articles→

On This Page

Introduction

Recent Posts

Debounced Search Input

How to Build a Debounced Search Input in React.js

7 May 2026

React js

React 19 Features Explained with React 18 vs React 19 Comparison

7 May 2026

Javascript

React Interview Questions and Answers 2026 | SSR, CSR, Hooks, Virtual DOM

7 May 2026

Top AI cource

AI Courses for Software Developers in 2026: Best Course, Salary & Career Path

30 March 2026

Bharat Ratna Award

Bharat Ratna Award Winners List 1954 to 2024: History, Facts and Full List

26 March 2026

Awards and Honours

Nobel Prize 2025 Winners, History, Categories, Indian Winners & Important Facts (Hindi + English)

26 March 2026

Javascript

JavaScript ES6+ Interview Questions & Concepts (Destructuring, Spread, Rest)

21 March 2026

React js

JavaScript Basics Explained: Variables, Data Types & Functions with Examples

21 March 2026

Javascript

JavaScript Arrays Explained with Examples Part 2 (Complete Beginner Guide)

20 March 2026

Javascript

JavaScript Arrays Explained with Examples (Complete Beginner Guide)

20 March 2026

Exambodh

Exambodh helps students prepare for aptitude, reasoning, GK, and verbal exams with topic-wise practice questions, simple explanations, and structured learning.

Quick Links

HomePlay QuizArticlesAbout UsContactPrivacy PolicyDisclaimerCopyright PolicyTerms & Conditions

Study Hubs

Latest ArticlesGeneral KnowledgeQuantitative AptitudeLogical ReasoningComputer AwarenessCurrent Affairs

Popular Categories

General KnowledgeIndian HistoryIndian PolityQuantitative AptitudeLogical ReasoningInterview Practice
Explore:HomePlay QuizArticlesContact

Copyright 2026 Exambodh - aptitude, reasoning & verbal practice.