-->

ESLint Airbnb ES6 and Redux Async Action Unexpecte

2019-05-15 01:39发布

问题:

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