I have a list when users click each item will change my array data.
my gender array first data is this:
[
{optionName: "Man", sex: 1, selected: true},
{optionName: "Woman", sex: 1, selected: false}
]
const [genderOption, setGenderOption] = useState(gender);
onItemPress = (item, i) => {
console.log('print i', i);
console.log('click genderOption', genderOption);
genderOption.map((value, index) => {
genderOption[index].selected = false;
} );
console.log('after genderOption', genderOption);
genderOption[i].selected = true;
console.log('final genderOption', genderOption);
// setGenderOption([...genderOption]);
// setTimeout(() => {
// console.log('timeOut !');
// setGenderOption([...genderOption]);
// }, 5000);
}
console.log('genderOption', genderOption);
return (
// my listView has onPress function trigger onItemPress()
);
when click index === 0
when click index === 1
It is when I use setTimeout


