Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Cannnot access this.context when getting Instance from Class in ReactJs

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;
}

}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!