I want to call method actionContext in Class BaseComponent from my Container function but this.context is undefined (I won't use class in Container.tsx) . Please Do you Know what I am missing in my syntax Instance ? Noting that I cannot modify the BaseComponentClass.js because we don't have right .
Container.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;
}
}