Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • React Documentation22টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Introduction
  • কেন React?
  • JSX
  • Component & Props
  • Conditional Rendering
  • Lists & Keys
  • Events
  • State (useState)
  • Forms
  • Lifting State
  • useEffect
  • useRef
  • Context
  • useReducer
  • Memoization
  • Custom Hooks
  • Children & Props
  • Error Boundaries
  • Portals & Fragments
  • Data Fetching
  • Performance
  • Todo Project
  1. Docs
  2. React
  3. useReducer — জটিল State
ReactIntermediate

useReducer — জটিল State

Reducer function, action object, dispatch — জটিল state logic-এর জন্য — বাংলায়।

6টি অংশবাংলা ভাষায়

Reducer কী?

`useReducer` জটিল state logic-এর জন্য — যেমন একাধিক update rule, বা জটিল object state। Reducer হলো pure function: (state, action) => newState।

Counter reducerjsx
jsx
import { useReducer } from "react";

const initialState = { count: 0, step: 1 };

function reducer(state, action) {
  switch (action.type) {
    case "increment":
      return { ...state, count: state.count + state.step };
    case "decrement":
      return { ...state, count: state.count - state.step };
    case "setStep":
      return { ...state, step: action.step };
    case "reset":
      return initialState;
    default:
      return state;
  }
}

function Counter() {
  const [state, dispatch] = useReducer(reducer, initialState);

  return (
    <div>
      <p>{state.count}</p>
      <button onClick={() => dispatch({ type: "increment" })}>+</button>
      <button onClick={() => dispatch({ type: "decrement" })}>−</button>
      <button onClick={() => dispatch({ type: "reset" })}>Reset</button>
      <input
        type="number"
        value={state.step}
        onChange={(e) => dispatch({ type: "setStep", step: +e.target.value })}
      />
    </div>
  );
}

Action object

Typed actionjsx
jsx
dispatch({ type: "todos/add", payload: { id, text } });
dispatch({ type: "todos/toggle", payload: id });
dispatch({ type: "todos/remove", payload: id });
useState নাকি useReducer?

সাধারণ কয়েকটি update → useState। একাধিক interrelated field, history/undo দরকার, বা logic দীর্ঘ → useReducer। লক্ষ্য জটিল logic-কে component-এর বাইরে পরিষ্কার ছাড়া।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরContext APIপরেরmemo, useMemo, useCallback
এই পেজে
Tech Tutor

বাংলায় ওয়েব ডেভেলপমেন্ট ডকুমেন্টেশন শিখুন — ধাপে ধাপে।

Homeসব ডকুমেন্টেশনQuick Startআমার নোটস

© 2026 Tech Tutor. বাংলায় শিখুন, বাংলায় গড়ুন।

mdanamolhasan1998@gmail.com