Updating a React Input text field with the value on onBlur event

前端 未结 3 983
星月不相逢
星月不相逢 2021-02-03 23:21

I have the following input field as below. On blur, the function calls a service to update the input value to the server, and once that\'s complete, it updates the input field.

3条回答
  •  悲哀的现实
    2021-02-04 00:12

    In order to have the input value editable you need to have an onChange handler for it that updates the value. and since you want to call a function onBlur, you have to bind that like onBlur={() => this.props.actions.updateInput()}

    componentDidMount() {
       this.setState({inputValue: this.props.inputValue});
    }
    handleChange = (e) => {
      this.setState({inputValue: e.target.value});
    }
    
     this.props.actions.updateInput(this.state.inputValue)} />
    

提交回复
热议问题