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
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-conceptsWiktionary defines a reducer as follows:
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: