Having a weird problem, So I have an array state called answers , and on button press I just want to add new object to this state. I am doing it with spread operator but somehow the new object always overrides the objects inside array. It is not appending. Snippet of my code given below
questions = [
{
no: 1,
key: '1',
question: 'Your gum bleeds when you brush your teeth',
},
{
no: 2,
key: '2',
question:
'Your gum appears reddish and slightly swollen, with rounded edges at the areas between teeth',
}]
const [answers, setAnswers] = useState([]);
<AppIntroSlider
renderItem={renderItem}
data={questions}
/>
in render item,
<Button
onPress={() => {
setAnswers([...answers, {no: item.no, ans: 'yes'}]);
}}>
Yes
</Button>
<Button
onPress={() => {
setAnswers([...answers, {no: item.no, ans: 'no'}]);
}}>
NO
</Button>
Having a weird problem, So I have an array state called answers , and on button press I just want to add new object to this state. I am doing it with spread operator but somehow the new object always overrides the objects inside array. It is not appending. Snippet of my code given below