S
S
Shiki002020-07-03 14:50:05
React
Shiki00, 2020-07-03 14:50:05

The state of the array changes only once. What to do?

At the beginning of the code, I declare arr and nexIdx:

let arr = Array(100).fill(1).map((v,i) => v + i);
let nextIdx = Math.floor((arr.length / 2) - 1);

Further, when I click on the "less" button, I reduce the array:
<Button title='Меньше' onPress={() => arr = arr.slice(0, nextIdx - 1)} />

When I click on the alert button, a reduced array (from 1 to 48) is alerted.
However, when you try to reduce the array and alert it again, nothing changes, the same thing is alerted, from 1 to 48. What should I do?
Here is the code:
https://snack.expo.io/@miralis/h

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Cheryabushkin, 2020-07-03
@Shiki00

Might be worth nextIdxupgrading too?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question