问题
What am I doing wrong? I have like three other async actions that have the same issue and can't fix it.
回答1:
When you take a look at the Arrow Function Documentation
(param1, param2, …, paramN) => expression
// equivalent to: => { return expression; }
the "Unexpected block statement surrounding arrow body" just means that you don't need a { return expression; }
block for your arrow function here, as the arrow function does return by default.
const getOptions = () => (dispatch, getState) => {}
is equivalent to
const getOptions = () => { return (dispatch, getState) => {} }
and therefore the block statement is unnecessary
回答2:
Not recommended:
You can always disable the arrow-body-style rule or configure it in a way that it doesn't give such errors.
Recommended:
const getOptions = () => ( dispatch, getState ) => {
const {user} = getState();
//rest of the code
}
This basically means that we don't have to write { return
thing when we are only returning w/o doing anything else
来源:https://stackoverflow.com/questions/37474957/eslint-airbnb-es6-and-redux-async-action-unexpected-block-statement-surrounding