0

I just saw this function

function reducer(_, { type, payload }) {

passed to useReducer this way

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

What is the meaning of the 1st parameter "_" in function reducer?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
  • 2
    It's a convention to mean "this variable is unused" – evolutionxbox Jul 05 '22 at 14:56
  • 2
    Just a clarification, `_` isn't being passed as a parameter to the function, it's the *name* of the parameter the function is accepting. Names generally don't matter outside of conventions/code styles/cosmetic. – Kevin B Jul 05 '22 at 14:57
  • It's just a variable name. If you are uncomfortable with it you can replace it with `x` or `i` or `ignore` and not change the meaning of the code – slebetman Jul 05 '22 at 22:01

0 Answers0