Search code examples
javascriptreduxarrow-functions

Arrow Function Declaration | Redux | =>


Why do we have => twice. Not able to understand the arrow function declaration.

const asyncFunctionMiddleware = storeAPI => next => action => {
  // If the "action" is actually a function instead...
  if (typeof action === 'function') {
    // then call the function and pass `dispatch` and `getState` as arguments
    return action(storeAPI.dispatch, storeAPI.getState)
  }

  // Otherwise, it's a normal action - send it onwards
  return next(action)
}

Solution

  • asyncFunctionMiddleware takes one argument storeAPI and returns an unnamed function. This unnamed function takes one argument next and returns another unnamed function. This unnamed function takes one argument action and returns a value.