首页 > 解决方案 > React Native 中的 super(props) 真的被弃用了还是只是一个 Vs 代码警告?

问题描述

我在 vs 代码中收到此警告以弃用 super(props),但我在警告消息中提到的链接中没有发现任何有用的信息。

警告:

'(props: any, context?: any): Component<any, any, any>' is deprecated
@deprecated
@see — https://reactjs.org/docs/legacy-context.html

我的组件类中的构造函数:

constructor(props) {
    super(props);
    this.state = {
    };
}

标签: reactjsreact-nativevisual-studio-codedeprecation-warning

解决方案


用这个:

constructor() {
    super();
    this.state = {
    };
}

推荐阅读