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

How to scroll to a specific element that can be modified? (React Native)

$
0
0

I created a glossary and want to have access to the content of a specific letter if I click on the letter (I have a list of letter at the top of my page).But here is the issue: while I've found how to scroll down, I didn't find how to scroll to a specific element.It seems to be quite easy in HTML (Scroll to a specific Element Using html) but I didn't find a solution for React Native.I tried to create a ScrollToElement then use ref to fix it but it does not change if my variable change, it always go to the bottom of the page. Here is the code simplified:

  const fieldRef = React.useRef<HTMLInputElement>(null);  const scrollToElement = () => fieldRef.current?.scrollIntoView();... return (<View><ScrollView><View>             {letter.map((letter) => {                return (<View><Text                      onPress={scrollToElement}>                      {letter.name}</Text></View>                );              })}</View><View>               {letter.map((letter) => {                  return(<View><div                    ref={fieldRef}><Text>                          {letter.name}</Text></div>                   )                  })}</View></ScrollView></View>)

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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