【发布时间】:2023-01-03 22:23:05
【问题描述】:
当我按下一个元素时,我希望能够滚动到一个元素。 (例如:我按 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
【问题讨论】:
标签: reactjs typescript react-native scroll