Wednesday, December 30, 2020

React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to make it fast. Faster solution for large data is here: see below:



import { FixedSizeList as List } from 'react-window';
import Select, { createFilter } from 'react-select';

<Select 

                        value={this.state.selectedReport}

                        onChange={this.handleChangeReport}

                        filterOption={createFilter({ ignoreAccents: false })} // this makes it fast!

                        components={{ CustomMenu }}

                        options={Reports}

                        isClearable={true}


                    />




const CustomMenu = props => {

            

            const { Reports, children, maxHeight, getValue } = this.props;

            const [value] = getValue();



            return (

                <List

                    height={150}

                    itemCount={children.length}

                    itemSize={35}

                >

                    {({ index, style }) => <div style={style}>{children[index]}</div>}

                </List>

            );

        };



No comments:

Post a Comment

React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to ...