Reactjs 在AutoSizer中包装时,将FixedSizeList滚动到最后一个元素
我使用AutoSizer进行了以下工作,但我需要列表在加载后滚动到最后一个元素,因此尝试获取对FixedSizeList的引用,但没有效果 我已经研究过使用forward refs和使用FixedSizeList outerementtype prop的HOC,但是我不知道如何正确地使用它Reactjs 在AutoSizer中包装时,将FixedSizeList滚动到最后一个元素,reactjs,react-virtualized,Reactjs,React Virtualized,我使用AutoSizer进行了以下工作,但我需要列表在加载后滚动到最后一个元素,因此尝试获取对FixedSizeList的引用,但没有效果 我已经研究过使用forward refs和使用FixedSizeList outerementtype prop的HOC,但是我不知道如何正确地使用它 const Row = ({ index, style }) => ( <div className={index % 2 ? "ListItemOdd" : "
const Row = ({ index, style }) => (
<div className={index % 2 ? "ListItemOdd" : "ListItemEven"} style={style}>
Row {index}
</div>
);
const Example = () => {
const listRef = createRef();
useEffect(() => {
//The ref is always null
if (listRef != null && listRef.current != null) {
listRef.current.scrollToItem(1000);
}
}, [listRef]);
return (
<div style={{ height: "80vh" }}>
<AutoSizer>
{({ height, width }) => (
<FixedSizeList
ref={listRef}
className="List"
height={height}
width={width}
itemCount={1000}
itemSize={35}
>
{Row}
</FixedSizeList>
)}
</AutoSizer>
</div>
);
};
const行=({index,style})=>(
行{index}
);
常量示例=()=>{
const listRef=createRef();
useffect(()=>{
//ref总是空的
if(listRef!=null&&listRef.current!=null){
listRef.current.scrollToItem(1000);
}
},[listRef]);
返回(
{({高度,宽度})=>(
{Row}
)}
);
};
如果我是你,我会在你的div上放置一个id
例如id={`fixed size row-${index}}}
然后使用make函数提供id:
const scrollToEl = (index) => {
const el = document.getElementById(`fixed-size-row-${index}`);
el.scrollIntoView();
}