ESLint Airbnb ES6 and Redux Async Action Unexpecte

2019-05-15 01:28发布

enter image description here

What am I doing wrong? I have like three other async actions that have the same issue and can't fix it.

2条回答
姐就是有狂的资本
2楼-- · 2019-05-15 01:54

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

查看更多
看我几分像从前
3楼-- · 2019-05-15 02:11

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

查看更多
登录 后发表回答