@grv1

Как исправить Warning Input is changing an uncontrolled input of type text to be controlled?

Лезет ошибка как исправить?
Warning: Input is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components


import React from 'react';
import createReactClass from 'create-react-class';

var Input = createReactClass({
    getDefaultProps() {
        return {
            classNames: 'input',
            value: '',
            onChange: function (event) {
                console.log(event, "don't set onChange");
            }
        };
    },
    getInitialState() {
        return {
            title: this.props.title,
        };
    },
    handleChange(event) {
        this.props.onChange(event);
        this.setState({value: event.target.value});
    },
    render() {
        return <div className={this.props.classNames}>
            <label>
                {this.state.title}
                <input type="text" value={this.state.value} onChange={this.handleChange} />
            </label>
        </div>;
    }
});

export {Input};
  • Вопрос задан
  • 14060 просмотров
Решения вопроса 1
RomReed
@RomReed
JavaScript, Flutter, ReactNative, Redux, Firebase
getInitialState() {
        return {
            title: this.props.title,
           value:"",
        };
    },

попробуйте так
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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