import { VariableSizeList as List, areEqual } from 'react-window';
import InfiniteLoader from 'react-window-infinite-loader';
const Demo = ()=>{
const ref = useRef();
const click = ()=>{
// 这里报错,ref没有scrollToItem方法
ref.scrollToItem(0)
}
return <div>
<Button onClick={click}>click</Button>
<ListWrap ref={ref}></ListWrap>
</div>
}
const ListWrap = ({ hasNextPage, isNextPageLoading, loadNextPage }) => {
return (
<InfiniteLoader isItemLoaded={isItemLoaded} itemCount={itemCount} loadMoreItems={loadMoreItems}>
{({ onItemsRendered, ref }) => {
return (
<List
ref={ref}
>
{Cell}
</List>
);
}}
</InfiniteLoader>
);
};
类似上面的代码, 如何获取List的实例ref呢?