Reputation: 176
Hi I'm just working into Redux and currently I'm just confused about a redux syntax given in a Redux-Cheat-Sheet Redux Cheat Sheet from Egghead:
const actionLogger = ({dispatch, getState}) =>
(next) => (action) =>
{ console.log(action); return next(action) }
So my question is: What does this "chained" arrow functions behave like?
Upvotes: 2
Views: 2862
Reputation: 887
If you want to use an arrow function:
const actionLogger = () => (dispatch, getState) => {
console.log(getState())
......
};
Upvotes: 1
Reputation: 6078
You can write it down as:
const actionLogger = function({dispatch, getState} /* this is store object */) {
return function(next) {
return function(action) {
console.log(action);
return next(action);
};
};
};
So basically chained arrow functions represent nested functions. It could be a bit confusing.
Detailed explanation how redux middleware works
Upvotes: 3