Why can't I change my input value in React even with the onChange listener

前端 未结 6 1214
再見小時候
再見小時候 2021-02-05 00:20

I am quite new to React and after going through some tutorials, I was trying the below code of mine.

I made one component, passed props to it from a store, on compo

6条回答
  •  春和景丽
    2021-02-05 00:24

    Unlike in the case of Angular, in React.js you need to update the state manually. You can do something like this:

     this.onTodoChange(e.target.value)}
    />
    

    And then in the function:

    onTodoChange(value){
            this.setState({
                 name: value
            });
        }
    

    Also, you can set the initial state in the constructor of the component:

      constructor (props) {
        super(props);
        this.state = {
            updatable: false,
            name: props.name,
            status: props.status
        };
      }
    

提交回复
热议问题