我是React新手,我正在通过最新版本的React学习React组件生命周期.我对下面部分代码的"super"调用被标记为不推荐的警告.我很难理解这一点,因为很多文档仍然使用"super",而且我不确定后续版本是什么,甚至从反馈中链接的完整文章来看也是如此.有什么 idea 吗?谢谢

class App extends Component {
  constructor(props) {
    super(props);
  }
}

以下是警告:

constructor React.Component<any, any, any>(props: any, context?: any): React:Component<any, any, any> (+1 overload)
@deprecated
@see - https://reactjs.org/docs/legacy-context.html
'(props: any, context?: any): Component<any, any, any>' is deprecated ts(6385)

推荐答案

可选的上下文参数似乎已被弃用,因为它引用了旧的React上下文(v16.3之前).你使用的是什么版本的React?

https://reactjs.org/docs/legacy-context.html

我没有使用React with TypeScript.也许 map 已经过时了.

Typescript相关问答推荐

交叉点对数字和布尔的处理方式不同

具有条件通用props 的react 类型脚本组件错误地推断类型

替换类型脚本类型中的多个特定字符串

"@ clerker/nextjs/server没有名为clerkMiddleware的导入成员'

调用另一个函数的函数的Typescript类型,参数相同

我应该使用什么类型的React表单onsubmit事件?

Angular 行为:属性类型从SignalFunction更改为布尔

更新为Angular 17后的可选链运算符&?&问题

在映射类型中用作索引时,TypeScrip泛型类型参数无法正常工作

Angular 错误NG0303在Angular 项目中使用app.Component.html中的NGFor

缩小并集子键后重新构造类型

有没有可能为这样的函数写一个类型?

部分更新类型的类型相等

Typescript 中相同类型的不同结果

基于未定义属性的条件属性

带有';的类型脚本嵌套对象可选属性错误满足';

TS不能自己推断函数返回类型

Typescript泛型调用对象';s方法

组件使用forwardRef类型脚本时传递props

TS 排除带点符号的键