@denis_21321321

Cannot read property 'props' of undefined?

При вводе в textarea вылазиет ошибка:
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>
        )}
}
  • Вопрос задан
  • 1430 просмотров
Решения вопроса 1
hzzzzl
@hzzzzl
теряется контекст this

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

// или

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


https://ru.reactjs.org/docs/faq-functions.html#how...
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы