Quiero llamar al método actionContext en Class BaseComponent desde mi función Container pero this.context no está definido (no usaré class en Container.tsx). Por favor, ¿sabe lo que me falta en mi instancia de sintaxis? Tenga en cuenta que no puedo modificar BaseComponentClass.js porque no tenemos right .
Contenedor.tsx:
import React, { useEffect, useState } from 'react'; export default function Container(props) { let BaseInstance = new BaseComponent(props); useEffect(()=>{ BaseInstance.actionContext(); // error },[]) return ( <div> hello </div> ); };BaseComponentClass.js:
import React, { Component, RefObject } from 'react'; export interface BaseProps { readOnly?: boolean; } export abstract class BaseComponent<P extends BaseProps, S, M extends ComponentInstanceParamsBase> extends Component<P, S> { static contextType = CommonsContext; protected componentRef: RefObject<any>; constructor(props: any) { super(props); this.componentRef = React.createRef() } get component() { return this.componentRef.current; } get actionContext() { return this.context.actionContext;//here there is no Context in this } get metadataContext(): M { return this.context.metadataContext; }}