How do I edit multiple input controlled components in React?

后端 未结 9 542
[愿得一人]
[愿得一人] 2020-12-04 09:01

I have a component that stores a contact object as state - {firstName: \"John\", lastName: \"Doe\", phone: \"1234567890} I want to create a form to edit this object but if I

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 09:41

    Here is generic one;

    handleChange = (input) => (event) => {
        this.setState({
            ...this.state,
            [input]: event.target.value
        });
    }
    

    And use like this;

    
    

提交回复
热议问题