I have an array of objects that is a length of 5,866 like formatted like this {label: "Luke Skywalker", value: "556534"}
and I am searching the objects and filtering by their label like so
onChange = (e) => {
e.persist()
this.setState({filter:e.target.value, filtered_array:
this.state.raw_user_list.filter(user =>
user.label.toLowerCase().indexOf(e.target.value.toLowerCase()) > -1)})
}
...
<form style={{paddingBottom:'10px'}}>
Filter: <input name="filter" value={this.state.filter} onChange={this.onChange} type="text" style={{
border: '1px solid #cccccc',
}}/>
</form>
this.state.filter is the value that is being types in to filter.
Before I was working with less than 1,000 entries initially and now with the user_list being 5,866 causes performance issues with the way I am filtering. I want to filter the data real-time when the user types.
e.target.value.toLowerCase()for each iteration. Store it in a scoped variable that you reference from the iteration function. That's one easy fix that should give you immediate results.onChangewould help if it is related to continuous typing