【发布时间】:2020-10-20 12:30:03
【问题描述】:
我的 react-app 组件中有两个功能
componentDidMount() {
if(Object.keys(this.props.praticiens).length>0)
Object.keys(this.props.praticiens).map((praticien) => {
if(this.props.praticiens[praticien].identifiant_user === getUrlParams(window.location.hash).identifiant_user)
this.setState({
praticien:this.props.praticiens[praticien].id_user
})
})
}
handleChangePraticien = (praticien) => {
this.setState({ praticien }, () => {
Object.keys(this.props.praticiens).map((praticien) => {
if(this.state.praticien === this.props.praticiens[praticien].id_user)
this.props.selectPraticienFunction(this.props.praticiens[praticien].identifiant_user);
})
})
}
当我运行它时,我得到:
Line 26:64: Expected to return a value in arrow function array-callback-return
Line 36:64: Expected to return a value in arrow function array-callback-return
比如第 26 行在 componentDidMount 上以 Object.keys(this.props.praticiens).map((praticien) => { 开头,而第 36 行在 handleChangePraticien 函数上是同一行
我该如何解决?
【问题讨论】:
-
您的 if 语句需要括号
{}。如果 if 语句中的行是单行,则只能删除它们。 -
@theblackgigant - 单个语句,而不是单行。它们都是单一的陈述。 (也就是说,我更喜欢总是在控制流状态上使用
{}。)
标签: javascript reactjs object eslint arrow-functions