title: ReactJS: replacing object from array with new value replaces whole array
body: <p>I have array <code>selectedItems</code> and when I try to update existing object:</p>
  
  <pre><code>i.e. [{lable: "one", uniqueId: 1}, {lable: "two", uniqueId: 1}] 
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>i.e. [{lable: "one", uniqueId: 1}, {lable: "two", uniqueId: 3}]
  </code></pre>
  
  <p>It replaces the whole array with:</p>
  
  <pre><code> [ { lable: "two", uniqueId: 3 }]
  </code></pre>
  
  <p>how can I avoid that? </p>
  
  <pre><code>handleChange = (label, uniqueId) =&gt; {
    const { selectedItems } = this.state
    const findExistingItem = selectedItems.find((item) =&gt; {
      return item.uniqueId === uniqueId;
    })
  
    if(findExistingItem) {
      selectedItems.splice(findExistingItem);
      this.setState(state =&gt; ({
        selectedItems: [...state.selectedItems, {
          label, uniqueId
        }]
      }))
    } else {
      this.setState(state =&gt; ({
        selectedItems: [...state.selectedItems, {
          label, uniqueId
        }]
      }))
    }
  }
  </code></pre>