I have initial state for the current value of multiple <Switch />
components contained inside a <SectionList />
as follows:
this.state = {
switchValues:[
[true],
[false, true], //i want to amend 'true' to be 'false'
[false],
],
};
How do I update the item at switchValues[1][1]
to be false
using setState?
There are other answers to similar questions such as this but the question relates to nested objects rather than arrays
Taking what I can from the linked answer I came up with
this.setState(
{
switchValues: [...this.state.switchValues,
[section][index]: value,
],
}
);
where both section
and index
are the correct int
values for the position in the array, but that doesn't update the correct element in the array.
Is this possible?