title: Splice method in React
body: <p>I'm trying to use <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/splice" rel="nofollow noreferrer">splice</a> to add new <code>components</code> into an array. If I use <code>concat</code> all the elements are added properly at the end, but what I also need is add at the beginning or in the middle of the array using <code>splice</code>. Any suggest ?</p>
  
  <pre><code>class App extends React.Component {
    state = {
      components: []
    };
  
    addNewElement = (element) =&gt; {      
      this.setState(prevState =&gt; ({   
        //Works fine
        //components: prevState.components.concat(element)
  
        components: prevState.components.splice(0, 0, element)
      }));
    };
  
  }
  </code></pre>