import React, { useReducer } from 'react';

function reducer(state, action) {
  switch (action.type) {
    case 'increment':
      return { count: state.count + 1 };
    case 'decrement':
      return { count: state.count - 1 };
    default:
      throw new Error();
  }
}

function Counter() {
  const [state, dispatch] = useReducer(reducer, { count: 0 });

  return (
    <div>
      <p>شمارنده: {state.count}</p>
      <button onClick={() => dispatch({ type: 'increment' })}>افزایش</button>
      <button onClick={() => dispatch({ type: 'decrement' })}>کاهش</button>
    </div>
  );
}