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

前端 未结 6 1210
再見小時候
再見小時候 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:34

    In React, the component will re-render (or update) only if the state or the prop changes.

    In your case you have to update the state immediately after the change so that the component will re-render with the updates state value.

    onTodoChange(event) {
            // update the state
        this.setState({name: event.target.value});
    }
    

提交回复
热议问题