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 时访问上下文?
谢谢!