我有一段代码:
`function App() {
const myRef = useRef(null);
const onWheel = e => {
e.preventDefault();
const containerScrollPosition = myRef.current.scrollLeft;
inputEl.current.scrollTo({
top: 0,
left: containerScrollPosition + e.deltaY * 0.35,
behaviour: "smooth"
});
};
return (
<div
className="App"
style={{
height: 440,
width: "100%"
}}
onWheel={onWheel}
>
<AutoSizer>
{({ height, width }) => (
<List
ref={myRef}
height={height}
itemCount={30}
itemSize={600}
layout="horizontal"
width={width}
>
{Grid}
</List>
)}
</AutoSizer>
</div>
);
}
当我myRef
用于List
组件时,myRef.current.scrollLeft
/myRef.current.clientHeight
返回undefined
(myRef.current
返回正确的组件节点)。如果我使用myRef
一切div.App
顺利。可能是什么问题呢?