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

178
Views
This.props undefined in my component and my constructor in well-defined

I'm stuck with a react native problem : I've my component with a (supposed) valid constructor, but I can't access to this.props

In my code :


//In another file
interface mainFunction {
    loaded: () => void,
    disconnect: () => void
}

interface disconnect {
    mainExport:mainFunction
}

class Disconnect extends Component<disconnect> {

    constructor(props:any) {
        super(props);
        console.log(props)
    }

    test() {
        console.log("Disconnect...");
        console.log(this.props);
    }    

    render() {
        return (
            //Some react render
        );
    }

export default Disconnect;

When I console log props in my constructor, there are functions that I give to this component, but in my test function this.props is undefined... I try to set this.props = props in the contructor by props is a readOnly propertie (I use TypeScript) What did I do wrong ?

EDIT____ I try to : create a new attribute to store my function :

class Disconnect extends Component<disconnect> {
    
    disconnect:any

    constructor(props:any) {
        super(props);
        console.log(this.props.mainExport.disconnect)
        this.disconnect = this.props.mainExport.disconnect
    }
}

But this.disconnect is unavariable in my other function

I try to bind my test function in the constructor but it doesn't work too ...

ANSWER_____ Okay so @Chris got the answer : I need to convert my test method to a variable :

//Old
test() {
        console.log("Disconnect...");
        console.log(this.disconnect_func);
        console.log(this.disconnect);
    }
//New
test = () => {
        console.log("Disconnect...");
        console.log(this.disconnect_func);
        console.log(this.disconnect);
}

and it works

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!