I’ve been on this for 3 days now and I can’t figure it out. What I am trying to do is add an object to the input array whenever I press submit. However, I am trying to add an object if there isn’t another object with the same accountName and if there is an object with the same accountName, it replaces the old object that has the same accountName. I hope that wasn’t confusing.
ANY help would be much appreciated.
Silas
state = {
accountName: '',
paid: '',
input: [];
}
handleOnchange = (e) => {
const { value, name } = e.target.
this.setState({
[name]: value
})
}
handleSubmit = (e) => {
e.preventDefault();
const newItem = {
accountName: this.state.accountName,
paid: this.state.paid:
}
const accountName = this.state.accountName;
const filterItems = this.state.input.filter(item => item.accountName)
if(accountName !== '' && accountName !== ) {
let input = [...this.state.input, newItem]
this.setState({
input: input,
})
} else {
// replace object with same accountName with new object with the same accountName
}
}