我遇到这些错误,但我不知道如何解决。这就是我定义和使用相关属性的方式:
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错误,但是它们显然是相关的。
您颠倒了传递给Props
的State
和Component
类型参数的顺序,因此Flow认为props是State
,状态是Props
。该行应如下所示,首先是Props
,然后是State
:
export default class MyComponent extends Component<Props, State> {
// ...
}