我希望能够滚动到一个元素,当我按下一个元素。(例如:我按下D键,它就向下滚动到字母D)。然而,虽然这里没有错误,但它没有向下滚动。下面是我的代码简化版:
const fieldRef = React.useRef<null | HTMLInputElement>(null);
const scrollToElement = () => fieldRef.current?.scrollIntoView();
...
<Text
onPress={() => {
{
scrollToElement;
} }}
>
Here
</Text>
...
<div ref={fieldRef}>
<Text> Hello</Text>
</div>
我使用这些来尝试纠正我的代码:How to add "refs" dynamically with react hooks?以及How to scroll to an element?和TypeScript error: Property 'scrollIntoView' does not exist on type 'never'. TS2339
1条答案
按热度按时间wribegjk1#
要向下滚动一定量: