skip to Main Content

I know how to use the useReducer hook in React, but I don’t understand why they are called "reducers".

The word "reduce" generally means "make smaller or less in amount". But it’s not clear to me why the React concept of a reducer has this name.

What is the reasoning behind calling this function a "reducer" in React? Some insight into the history and meaning behind this terminology would be greatly appreciated!

2

Answers


  1. The reason it’s called like that is because useReducer is the modern alternative to Redux. And in Redux they are called reducers: https://redux.js.org/introduction/core-concepts

    Login or Signup to reply.
  2. Wiktionary defines a reducer as follows:

    A function that takes state and action as arguments and returns the next state of the app.

    Which is exactly what React useReducer hook takes as an argument.

    This concept is not specific to React or even Javascript.

    Another example of function that takes a reducer as an argument is the Array.reduce method:

    const array = [1, 2, 3];
    const sum = array.reduce((accumulator, current) => accumulator + current, 0);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search