score:3

Accepted answer
this.setState({formData:{name: this.state.formData.name, address:value}});`

this.setState({formData:{name:value, address: this.state.formData.address}});`

score:-2

this.state = {
  showCreateForm: false,
  name: "...",
  address: "..."
}

score:0

function handleChangeName(event) {
    const value = event.target.value;
    this.setState((prevState)=>({ formData: { name: value, address: prevState.formData.address }}),
    ()=>{ console.log(this.state.formData)});
}

function handleChangeAddress(event) {
    const value = event.target.value;
    this.setState((prevState)=>({ formData: { name: prevState.formData.name, address: value}}),
    ()=>{ console.log(this.state.formData)});
}

score:4

this.setState({...this.state.formData, address: value})

Related Query

More Query from same tag