Skip to main content
Engineering41 words1 min read

Understanding React Hooks

Written by

A deep dive into useState and useEffect with visual diagrams.

React Hooks revolutionized how we write components. Let's explore the core hooks.

The State Hook: useState

The useState hook allows you to add state to function components.

TSX
import { useState } from 'react';

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

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

The Effect Hook: useEffect

useEffect handles side effects like data fetching or subscriptions.

Dependency Array Logic

C

Written by

Code Gardener