D
D
denis_213213212020-09-29 15:41:56
JavaScript
denis_21321321, 2020-09-29 15:41:56

Cannot read property 'props' of undefined?

When entering into a textarea, an error pops up:
Cannot read property 'props' of undefined

class Mes1 extends React.Component{
    constructor(props) {
        super(props)
        this.props = props;
        window.two = props;  // пропсы приходят
    };

    changePostText(e)
    {
        console.log(e.target.value);
        let text = e.target.value;
        this.props.changePostText(text);  // can't read property 'props' of undefined

    }
    render()
    {
        return (
            <div>
                <textarea onChange={this.changePostText} value={this.props.postText} />
            </div>
        )}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-09-29
@denis_21321321

the this context is lost

changePostText = e => { console.log(this.props) }

// или

onChange={this.changePostText.bind(this)}

https://ru.reactjs.org/docs/faq-functions.html#how...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question