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

decrementing after array mapping not working

$
0
0

I have a function "Next "that maps an array like in the example below and after incrementing the element I am doing something, but I also have another function "Prev" it pretty much does a similar mapping but in that function, I am decrementing the element. The Next function works fine but the Prev function doesn't, can someone please help me with this?

I am mapping an array of object

[   {"id":"v82b3a65","name":"Name"   },   {"id":"u0b26551","name":"Name2"   }]

my functions :

const Next = () => {  array.items.map((item, key, element) => {    var next = element[key ++];    setId(next.id);  });};const Prev = () => {  array.items.map((item, key, element) => {    var prev = element[key --];    setId(prev.id);  });};render(<View><Button title={'Prev'} onPress={Prev}/><Button title={'Next'} onPress={Next}/></View>)

I am using those functions in onPress of buttons

The result I need: on Next button press I want it to set setID = next objects id and on Prev button press I want to set setID = previous object id


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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