Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native Typescript : scroll with useRef and scrollIntoView

$
0
0

I wanted to be able to scroll to an element when I press on a element. (ex : I press D and it scroll down to the letter D) . Howether while there is no error here, it is not scrolling down.Here is my code simplified:

const fieldRef = React.useRef<null | HTMLInputElement>(null);  const scrollToElement = () => fieldRef.current?.scrollIntoView();

...

<Text                      onPress={() => {                        {                          scrollToElement;                        } }}>                          Here</Text>

...

<div ref={fieldRef}><Text> Hello</Text></div>

I used these to try to correct my code:How to add "refs" dynamically with react hooks?as well asHow to scroll to an element?as well asTypeScript error: Property 'scrollIntoView' does not exist on type 'never'. TS2339


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>