Reactjs 尽管单击其他选项,但无法更改React本机选择器

Reactjs 尽管单击其他选项,但无法更改React本机选择器,reactjs,react-native,Reactjs,React Native,我是react native的新手,我正在尝试使用react picker显示下拉列表 我可以成功地显示标签,问题是每次我选择的项目,它总是回到第一个选项这里是我的代码 import React,{useState,useffect}来自“React”; 从“react native”导入{Text,TextInput,样式表,视图,按钮,选择器}; 从“../hooks/NewsPost”导入新闻稿 从“../hooks/CategoriesGet”导入CategoriesGet const

我是react native的新手,我正在尝试使用react picker显示下拉列表

我可以成功地显示标签,问题是每次我选择的项目,它总是回到第一个选项这里是我的代码

import React,{useState,useffect}来自“React”;
从“react native”导入{Text,TextInput,样式表,视图,按钮,选择器};
从“../hooks/NewsPost”导入新闻稿
从“../hooks/CategoriesGet”导入CategoriesGet
const CreateScreen=({navigation})=>{
const[category_id,setCategoryID]=useState(0)
常量[categoriesGetApi,categories,errorMessageCategory]=CategoriesGet()
const[newspastapi,errorMessage]=NewsPost()
useffect(()=>{
categoriesGetApi()
}, [])
{
setCategoryID({itemValue})
console.log({itemValue})
}}
>
{
类别.地图((项目)=>{
返回(
)
})
}
我使用map循环的类别是一个对象数组

[
  {"attributes": {"id": 1, "name": "Sport"}, "id": "1", "type": "category"}, 
  {"attributes": {"id": 2, "name": "Politics"}, "id": "2", "type": "category"}, 
  {"attributes": {"id": 3, "name": "Entertainment"}, "id": "3", "type": "category"}
]

看起来您正在将
category\u id
设置为对象
{itemValue:itemValue}
,而不仅仅是值

改变
setCategoryID({itemValue})
setCategoryID(itemValue)


我也不知道
categoryName
是从哪里来的。如果是
category\u id

是的,我刚刚更改/编辑了上面的问题,并且问题解决了,我会在6分钟后接受答案(分钟)谢谢!