我已经为ESLint添加了Airbnb配置,以鼓励使用属性和状态解构。我很喜欢它,但是当我在组件中定义状态时遇到了一个问题。
class MyComponent extends Component {
state = {
animation: this.props.active ? 1 : 0
}
我遇到了一个错误
[eslint] 必须使用解构的方式对 props 进行赋值 (react/destructuring-assignment)
我不确定如何在这里正确地对 props 解构出 active
?
通常情况下 const {active} = this.props
可以使用,但是每当我将其放在 state 内部或周围时,我会遇到意外的语法错误。