Replacing an object with a new object in React state

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
     }
}

I’m not quite sure but maybe you need something like this:
(The example is independent of your code)

function replaceOrAdd(arr, newObject) {
  let flag=false;
  
  // [1] using map for replacing
  let m = arr.map(function(v,i){
    if(v.name==newObject.name) {
      flag=true;
      return newObject;
    }
    return v;
  });
  
  // [2] if there is nothing to replace: add newObject
  if(!flag) m.push(newObject);
  return m;
}

let baseData = [{name:"Doe", age:42}, {name:"Myer", age:33}];
let new1 = {name:"Doe", age:66}; // replace
let new2 = {name:"Baker", age:99}; // add

let replace1 = replaceOrAdd(baseData, new1);
replace2 = replaceOrAdd(replace1, new2);
console.log(replace2);
/* 0: {name: "Doe", age: 66}
1: {name: "Myer", age: 33}
2: {name: "Baker", age: 99} */