Member-only story

React Hooks Overview: A Deep Dive into useState, useEffect, and useContext

Ruchir Gupta
3 min readJan 2, 2025

React Hooks are special functions introduced in React 16.8 that allow you to use state and lifecycle features in functional components, eliminating the need for class components.

What are Hooks?

Hooks are functions that “hook into” React state and lifecycle features. They enable you to:

  1. Manage state (useState).
  2. Handle side effects (useEffect).
  3. Share logic between components without modifying their structure (useContext and custom hooks).

Common React Hooks

1. useState: Managing Component State

The useState hook allows functional components to have local state. It returns an array with two elements:

  • The current state.
  • A function to update the state.

Syntax:

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

Example: Counter

import React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<div>
<h1>Count: {count}</h1>
<button…

--

--

Ruchir Gupta
Ruchir Gupta

Written by Ruchir Gupta

Software Developer at Accenture India, Ex-Software Engineer at Roblox Corporation.

No responses yet