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

React Native, issue with setting the state (setState)

$
0
0

I have an issue with my code : when I try to convert a variable to a state, my variable state pass2 that was incremented became a number 3 for all my implementations while my former variable was incremented normally. I tried using useEffect but it returns me a blank page. Same if I try to replace my former variable by my state.Why is it that the state will always be the same number?Here is the code:

  const [pass2, setPass] = useState(0);  let pass = 0;...<View>{letter.map((letter) => {<FlatList                    data={letter.description}                    numColumns={2}                    keyExtractor={(_, index) => index.toString()}                    renderItem={({ item }) => {                      if (pass >= letter.description?.length) {                        pass = 0;                        setPass((pass2) => 0);                        pass2;                      }return(<View><Text>                            {letter.description[pass]}                            {pass++}                            {setPass((pass2) => pass2 + 1)}                            {pass2}</View></Text>)})}

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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