简体   繁体   English

具有动态列表维度的 React-Window

[英]React-Window with dynamic list dimensions

I'm trying to add react-window to my stack, however all examples require the width and height of the list to be statically defined like this:我正在尝试将react-window添加到我的堆栈中,但是所有示例都需要像这样静态定义列表的宽度和高度:

import { FixedSizeList as List } from 'react-window';
 
const Column = ({ index, style }) => (
  <div style={style}>Column {index}</div>
);
 
const Example = () => (
  <List
    height={75}
    itemCount={1000}
    itemSize={100}
    layout="horizontal"
    width={300}
  >
    {Column}
  </List>
);

In my current code, the width and height are defined as follows:在我当前的代码中,宽度和高度定义如下:

 <div
                style={{
                    overflowY: 'scroll',
                    height:
                        width >= 600 &&
                        (isFirefox() ? '100%' : '-webkit-fill-available'),
                    width: isFirefox()
                        ? '-moz-available'
                        : '-webkit-fill-available',
                }}
            >
                {items.map(item => <MyItem ... />}

           </div>

As you can see, my width and height are defined as 100% or webkit-fill-available .如您所见,我的宽度和高度定义为 100% 或webkit-fill-available

How can I adapt this to make it work with react-window or react-virtualized ?我该如何调整它以使其与react-windowreact-virtualized一起使用?

I would suggest using the same logic as className in react-window , so we are going to write it like:我建议在react-window中使用与className相同的逻辑,因此我们将其编写为:

const Example = () => (
  <List
    height={75}
    itemCount={1000}
    itemSize={100}
    layout="horizontal"
    width={300}
    className={isFirefox() ? 'FirefoxClass' : 'anotherStyle'}
  >
    {Column}
  </List>
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM