TypeError:未定义不是一个函数(接近' ... oigachievements.map ...')
我正在尝试为列表中的每个项目创建一个单独的交换机,每个项目默认情况下,它具有错误,我只想在单击React Native Switch时将其保留,但是我'每当我尝试激活或禁用此开关时,会出现此错误
import {Switch} from "react-native";
const [mockAchievements, setAchievements] = useState([
{
isEnabled: false,
},
{
isEnabled: false,
}]
function toggleSwitch(value, index) {
setAchievements((prevAchievements) => {
return {
...prevAchievements,
[index]: {
...prevAchievements[index],
isEnabled: value,
},
};
});
}
<Switch
trackColor={{ false: "#E9E9E9", true: "#EEF8FC" }}
thumbColor={item.isEnabled ? "#006993" : "#CBCBCB"}
ios_backgroundColor="#CBCBCB"
onValueChange={(value) => {
toggleSwitch(value, index);
}}
value={item.isEnabled}
/>
I'm trying to create an individual switch for each item in the list, each item has an isEnabled that by default it has which is false, and I just want to leave it true when I click on the react native switch, but I'm getting this error whenever I try to activate or disable this switch
import {Switch} from "react-native";
const [mockAchievements, setAchievements] = useState([
{
isEnabled: false,
},
{
isEnabled: false,
}]
function toggleSwitch(value, index) {
setAchievements((prevAchievements) => {
return {
...prevAchievements,
[index]: {
...prevAchievements[index],
isEnabled: value,
},
};
});
}
<Switch
trackColor={{ false: "#E9E9E9", true: "#EEF8FC" }}
thumbColor={item.isEnabled ? "#006993" : "#CBCBCB"}
ios_backgroundColor="#CBCBCB"
onValueChange={(value) => {
toggleSwitch(value, index);
}}
value={item.isEnabled}
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改用此功能
如果我没有错,您的功能将返回状态为对象而不是数组
Use this function instead
and if I am not wrong, your function returns the state as an object instead of an array