构造函数中未定义上下文 - 反应

问题描述

export default class Printer extends React.PureComponent<PrinterProps> {
    static contextType = PrinterContext;

    constructor(props: PrinterProps,context: PrinterInterface){
        super(props,context);
        this.PrinterInfo = getPrinterInfo(this.context);
}

我需要将上下文传递给 super 以便能够在构造函数中访问它。

在他们的最新文档中没有将上下文传递给构造函数 -

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

但它存在于旧版 API 文档中。

https://reactjs.org/docs/legacy-context.html#referencing-context-in-lifecycle-methods

由于将上下文传递给 super 将在 17 及更高版本中被弃用,有什么方法可以在将上下文传递给构造函数中的 super 时访问上下文?

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)