What is the best way to render large list of data in a searchable react select dropdown? I've looked at windowing, where DOM nodes are created only for items that are visible in the view port. This can be done by using the react-window package alongside react-select. However, I want to know if there are better approaches than this.
This is the windowing implementation using react-window and react-select
import React, { Component } from "react";
import ReactDOM from "react-dom";
import Select from "react-select";
import { FixedSizeList as List } from "react-window";
import "./styles.css";
const options = [];
for (let i = 0; i < 10000; i = i + 1) {
options.push({ value: i, label: `Option ${i}` });
}
const height = 35;
class MenuList extends Component {
render() {
const { options, children, maxHeight, getValue } = this.props;
const [value] = getValue();
const initialOffset = options.indexOf(value) * height;
return (
<List
height={maxHeight}
itemCount={children.length}
itemSize={height}
initialScrollOffset={initialOffset}
>
{({ index, style }) => <div style={style}>{children[index]}</div>}
</List>
);
}
}
const App = () => <Select components={{ MenuList }} options={options} />;
ReactDOM.render(<App />, document.getElementById("root"));