import React, { useState } from 'react';
import { View, Pressable,Text } from 'react-native';
export default function App(){
const [count, setcount] = useState([2,5,4,1,8])
const [b, setb] = useState(0)
return (
<View>
<Pressable onPress ={ () => setb(b+1)}>+</Pressable>//Updating value and showing from array
<Text> {count[b]} </Text>
<Pressable onPress ={ () => setb(b-1) }>-</Pressable>//Same for decrements
</View>
)
}
The code doesn't work properly for the first and last value means it is going to index -1 and also out of bound at the last index. Please highlight where I am doing wrong.