ESLint Airbnb ES6 and Redux Async Action Unexpected block statement surrounding arrow body

霸气de小男生 提交于 2019-12-07 15:38:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!