I am using React Virtualized to render a list with expandable panels. The issue is that when a panel expands, all 500+ rows inside it are loaded at once, making the UI very slow.
The outer list is virtualized, but I also want to virtualize the rows inside the expanded panel so only visible rows are rendered.
Wrapping the inner rows with List from react-virtualized, but it didn’t work as expected. I am facing issues with height calculations when trying to virtualize both levels. How can I efficiently virtualize the inner rows inside an expanded panel?
Here’s my CodeSandbox link showing the issue:
Reference
I am using React Virtualized to render a list with expandable panels. The issue is that when a panel expands, all 500+ rows inside it are loaded at once, making the UI very slow.
The outer list is virtualized, but I also want to virtualize the rows inside the expanded panel so only visible rows are rendered.
Wrapping the inner rows with List from react-virtualized, but it didn’t work as expected. I am facing issues with height calculations when trying to virtualize both levels. How can I efficiently virtualize the inner rows inside an expanded panel?
Here’s my CodeSandbox link showing the issue:
Reference
Share Improve this question edited Mar 8 at 15:23 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Mar 8 at 13:41 Aman SadhwaniAman Sadhwani 3,5683 gold badges19 silver badges28 bronze badges 2- 1 Do you need to see multiple panels at once? If yes, have three separate togglable lists. If not, have one list populated with the filtered entries of the selected category. – moonwave99 Commented Mar 8 at 15:15
- The panels are already separated; the question is how to virtualize the rows inside these panels. – Aman Sadhwani Commented Mar 8 at 15:22
1 Answer
Reset to default 1When you don't set a fixed height for the inner container, the virtualization engine can't determine which rows are visible, rendering every row in the expanded section. By wrapping the inner list in a container with a specific height (say 300px), you let React Virtualized know how much space it has to work with. Then, using an AutoSizer, it calculates the available width and height, and the List component only renders the rows that fit within that space.
Maybe like this :
{expanded && (
<div style={{ height: 300 }}>
<AutoSizer>
{({ height, width }) => (
<List
width={width}
height={height}
rowCount={rows.length}
rowHeight={50}
rowRenderer={innerRowRenderer}
/>
)}
</AutoSizer>
</div>
)}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744894793a4599629.html
评论列表(0条)