I am attempting to search through an array of over 15000+ values. I would like to do this using react-autocomplete, and to render such a large list of data I am using react-virtualized List component.
Here is my attempt. The problem I am facing is on I can not type anything into the search bar, not sure why. Feel free to either edit my current code or to totally rewrite/refactor the code as I am still testing what the best approach is.
***In the codesandbox it is not rendering https://codesandbox.io/s/nifty-meninsky-qirjk?file=/src/index.js
On my local machine the List renders when I click on the search bar, but I cannot type into the box
let searchBar;
let searchingFor;
if (clientList !== undefined) {
const renderItem = (item) => {
return <div>{item.name}</div>;
};
const onSelect = (item) => this.setState({ selection: item });
console.log(clientList[1].clientName);
const renderMenu = (items, searchingFor, autocompleteStyles) => {
return (
<List
width={500}
height={600}
rowHeight={50}
rowCount={clientList.length}
rowRenderer={({ key, index, style, parent }) => {
const client = clientList[index];
return (
<div key={key} style={style}>
{" "}
<h2>{client.clientName}</h2>
</div>
);
}}
/>
);
};
const searchTerm = searchingFor;
let data = searchTerm
? clientList.filter((item) => item.clientName.includes(searchTerm))
: [];
searchBar = (
<div>
{" "}
<Autocomplete
renderItem={renderItem}
items={data}
getItemValue={(item) => item.clientName}
value={searchingFor}
onChange={(e, value) => (searchingFor = value)}
onSelect={onSelect}
renderMenu={renderMenu}
/>
</div>
);
}
return (
<div>
<Grid container>
<Box>{searchBar} </Box>
</Grid>
</div>
);