PropType已定义,但从未使用prop-而是吗?

问题描述 投票:0回答:1

我遇到这些错误,但我不知道如何解决。这就是我定义和使用相关属性的方式:

type State = {
  isLoading: boolean // <-- 'isLoading' PropType is defined but prop is never used
};
type Props = {};


export default class MyComponent extends Component<State, Props> {
  constructor(props) {
    super(props);
    this.state = { isLoading: true };
  }
 render() {
    const {isLoading } = this.state; // <-- property `isLoading` is missing in  `Props` [1].Flow(InferError)
index.js(25, 52): [1] `Props`
    if (isLoading)
      return (
        <Container>
          <Spinner color="blue" />
        </Container>
      );
 }
}

所以有定义,并且使用了它们(当我进行结构分解时)。我也不了解Flow错误,但是它们显然是相关的。

eslint flowtype airbnb
1个回答
0
投票

您颠倒了传递给PropsStateComponent类型参数的顺序,因此Flow认为props是State,状态是Props。该行应如下所示,首先是Props,然后是State

export default class MyComponent extends Component<Props, State> {
    // ...
}

查看Flow docs on React components了解更多。

© www.soinside.com 2019 - 2024. All rights reserved.