title: How to filter an array with fetched data in React.js?
body: <p>I'm trying to filter an array with fetched list of users. Users are stored in component state. I want to filter it by text from input. </p>
  
  <p>Problem: When I enter letters the list is filtering, but when I delete letters result remains unchanged. </p>
  
  <p>Thanks for help!!!</p>
  
  <pre><code>class App extends React.Component {
      state = {
          isLoading: true,
          users: [],
          error: null
      }
  
      fetchUsers() {
          fetch(`https://jsonplaceholder.typicode.com/users`)
          .then(response =&gt; response.json())
          .then(data =&gt;
              this.setState({
                users: data,
                isLoading: false,
              })
          )
          .catch(error =&gt; this.setState({ error, isLoading: false }));
      }
  
      componentDidMount() {
          this.fetchUsers();
      }
  
      onChangeHandler(e) {
          console.log(e.target.value);
          let newArray = this.state.users.filter((d)=&gt;{
              let searchValue = d.name.toLowerCase();
              return searchValue.indexOf(e.target.value) !== -1;
          });
          console.log(newArray)
          this.setState({
              users:newArray
          })
      }
  
      render() {
          const {isLoading, users, error} = this.state;
              return (
                  &lt;div&gt;
                      &lt;h1&gt;Users List&lt;/h1&gt;
                      &lt;input type="text" value={this.state.value} placeholder="Search by user name..." onChange={this.onChangeHandler.bind(this)}/&gt;
                      {error ? &lt;p&gt;{error.message}&lt;/p&gt; : null}
                      &lt;ol&gt;
                      {!isLoading ? (
                          users.map(user =&gt; {
                              const {username, name, id} = user;
                              return (
                                  &lt;li key={id}&gt;
                                      &lt;p&gt;{name} &lt;span&gt;@{username}&lt;/span&gt;&lt;/p&gt;
                                  &lt;/li&gt;
                              );
                          })
                      ) : (
                          &lt;h3&gt;Loading...&lt;/h3&gt;
                      )}
                      &lt;/ol&gt;
                  &lt;/div&gt;
              );
        }
  }
  
  export default App;
  </code></pre>