S
S
Sergey Melnikov2018-09-06 11:46:04
JavaScript
Sergey Melnikov, 2018-09-06 11:46:04

How to overcome the error Uncaught TypeError: Cannot read property 'validateData' of undefined?

This error occurs in the code:

class Index extends React.Component {
    constructor (props, context) {
        super(props, context);
        this.state = {isHidden: true};
        this.validateData = this.validateData.bind(this);

    validateData (){

    };

    sendData() {
        //Валидация
        this.validateData();
      
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yanis_kondakov, 2018-09-06
@azazel_live

You need to pass the context to the sendData method. One option in the constructor is to write:
this.sendData = this.sendData.bind(this);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question