frontend-challenges icon indicating copy to clipboard operation
frontend-challenges copied to clipboard

385 - useReducer - react

Open jsartisan opened this issue 3 months ago • 0 comments

useReducer.js

import { useState } from "react";

export function useReducer(reducer, initialState) {
  const [state, setState] = useState(initialState);

  const dispatch = (action) => {
    setState(() => reducer(state, action));
  };

  return [state, dispatch];
}

jsartisan avatar Aug 18 '25 16:08 jsartisan