I have an API and I need to set the switch button separately for each
item. I read different answers but didn’t solve my problem as I tried
all of the answers.
const results = [
{
Id: "IySO9wUrt8",
Name: "Los Stand",
Category: "Mexican",
Status: true,
},
{
Id: "IySO9wUrt8",
Name: "Los Stand 2",
Category: "Burger",
Status: true,
},
{
Id: "IySO9wUrt8",
Name: "Los Stand 3",
Category: "BBq",
Status: true,
},
];
in the above code I need to set the Status in switch . If status is
true then the switch will be ONfor all the code I share the link of expo for live editing
2
Answers
You need to create a component that receives the item information, and inside the component update the state individually for each switch, otherwise the state is shared among the number of items you have.
The link for Expo is here
If you turn your results into a state you can do it link:
If converting result into state is not desireable then you can move renderItem into its own file so that it can have state of its own link: