title: Check if item exists in array React
body: <p>I'm trying to check if an item exists in my array <code>data</code> and if it does then prevent it from being added to the array.</p>
  
  <p>The <code>handleCheck</code> function will return true if an items already exists in the array but I'm not sure how to then use this to prevent the item from being added to the array.</p>
  
  <p>I have attempted to use it in the <code>handlePush</code> function  <code>this.handleCheck(item) == false ?</code> it should check if it's false and if so then push, if it returns true it should say it exists but at the moment this is not working as it will push to the array even if the item exists and it will never console.log 'exists`</p>
  
  <p>How can I change my handlePush function to use handleCheck and prevent an item that already exists in the array to be added again?</p>
  
  <p><a href="https://www.webpackbin.com/bins/-KpnhkEKCpjXU0XlNlVm" rel="noreferrer">https://www.webpackbin.com/bins/-KpnhkEKCpjXU0XlNlVm</a></p>
  
  <pre><code>import React from 'react'
  import styled from 'styled-components'
  import update from 'immutability-helper'
  
  const Wrap = styled.div`
    height: auto;
    background: papayawhip;
    width: 200px;
    margin-bottom:10px;
  `
  
  export default class Hello extends React.Component {
    constructor() {
      super()
      this.state = {
      data: []
      }
  
      this.handlePush = this.handlePush.bind(this)
      this.handleRemove = this.handleRemove.bind(this)
      this.handleCheck = this.handleCheck.bind(this)
    }
  
    handlePush(item) {
  
      this.handleCheck(item) == false ?
      this.setState({
      data: update(this.state.data, {
        $push: [
          item
        ]
      })
      })
  
     : 'console.log('exists')
    }
  
     handleRemove(index) {
      this.setState({
      data: update(this.state.data, {
        $splice: [
          [index,1]
        ]
      })
      })
    }
  
  handleCheck(val) {
   return this.state.data.some(item =&gt; val === item.name);
  }
  
    render() {
      return(
      &lt;div&gt;
          &lt;button onClick={() =&gt; this.handlePush({name: 'item2'})}&gt;push&lt;/button&gt;
          &lt;button onClick={() =&gt; this.handlePush({name: 'item3'})}&gt;push item3&lt;/button&gt;
          {this.state.data.length &gt; 1 ? this.state.data.map(product =&gt; 
            &lt;Wrap onClick={this.handleRemove}&gt;{product.name}&lt;/Wrap&gt;) : 'unable to map' } 
          {console.log(this.state.data)}
          {console.log(this.handleCheck('item2'))}
          {console.log(this.handleCheck('item3'))}
        &lt;/div&gt;
      )
  
    }
  }
  </code></pre>