Inheritance class in different files parent “this” result to undefined

The handleNameBlur is used in another context (Class ExampleForm) so you should bind it in ParentChecker to keep the context.

export default class ParentChecker {
    constructor() {
        this.data = {
            'foo': 'bar',
        };

        this.handleNameBlur = this.handleNameBlur.bind(this);
    }
    handleNameBlur(e) {
        console.log(this.data); // <=== "this" result to undefined.
    /* ... */
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top