title: React native: remove item from ListView
body: <p>I'm using React Native (<code>0.12.0</code>) on Android and have a ListView component on my page. I want to be able to remove items from the list.</p>
  
  <p>This ListView looks like this:</p>
  
  <pre><code>&lt;ListView
      dataSource={this.state.dataSource}
      renderRow={this._renderStory}
      onEndReached={this._getStories}
      /&gt;
  </code></pre>
  
  <p>The <code>rowHasChanged</code> method looks like this.</p>
  
  <pre><code>this.state = {
      dataSource: new ListView.DataSource({
          rowHasChanged: (row1, row2) =&gt; {
              return row1 !== row2;
          },
      }),
      loaded: false,
  };
  </code></pre>
  
  <p>All of that works just fine.</p>
  
  <p>Now, to remove an item I have this code:</p>
  
  <pre><code>var indexOfItem = this._data.findIndex((item) =&gt; item.id === story.id);
  this._data.splice(indexOfItem, 1);
  
  this.setState({
      dataSource: this.state.dataSource.cloneWithRows(this._data),
  });
  </code></pre>
  
  <p>I can confirm that the item is being removed from <code>this._data</code>. <code>this.state.dataSource._cachedRowCount</code> is reduced by one as it should be. The state is being updated and a render cycle triggered. But the item isn't removed from the page. What's more, if I put a console log in <code>this._renderStory()</code>, the only thing happening is it renders a <em>new</em> row at the bottom of the list.</p>
  
  <p>Am I missing something? Is there another step I need to do?</p>
  
  <p>A similar question was asked here but he never got an answer about removing a row. <a href="https://stackoverflow.com/questions/29351259/how-to-add-delete-item-into-listview">How to add/Delete item into ListView?</a></p>
  
  <p>All the other examples I've seen around the place lack an example of removing an item.</p>
  
  <p>UPDATE: Thanks, it required passing a clone of the array AND setting a key (sorry can only accept one answer). But this meant the whole list was being rendered. In the end I just set a 'removed' property on the items, tested for that property changing and returned null in the render method if an item was flagged as remove, this was faster than re-rendering all items.</p>