更新React Hook Object元素



我有一个下拉列表,用户可以在其中选择要设置待办事项的日期。基于我将添加true的日期。

通过选择字段(例如Monday(,如果用户选择afternoon并且也选择evening,则下午字段一定不会受到影响。这样做可能吗。请帮帮我。

这是我的代码

const ToDo = () =>{
const [selectedCat, setSelected] = useState('')
const [mon, setMon] = useState([{
'morning':[],
'afternoon':[],
'evening':[]
}])
const days = [
{itemName: "Select a day"},{itemName: "Monday"},
{itemName: "Tuesday"},
{itemName: "Wednesday"},{itemName: "Thursday"},
{itemName: "Friday"},{itemName: "Saturday"},
{itemName: "Sunday"}
]
const whichDay = () =>{
switch(selectedCat){
case selectedCat === 'Monday':
setMon({
"morning": true
})
default:
break
}
}
return(
<Picker
mode="dropdown"
selectedValue={selectedCat}
onValueChange={(itemValue, itemIndex) => setSelected(itemValue) && whichDay()}
>
{category.map((item, index) => (
<Picker.Item
label={item.itemName}
value={item.itemName}
index={index}
/>))}
</Picker>
)
}
const ToDo = () =>{
const [selectedCat, setSelected] = useState('')
const [mon, setMon] = useState([{
'morning':[],
'afternoon':[],
'evening':[]
}])
const days = [
{itemName: "Select a day"},{itemName: "Monday"},
{itemName: "Tuesday"},
{itemName: "Wednesday"},{itemName: "Thursday"},
{itemName: "Friday"},{itemName: "Saturday"},
{itemName: "Sunday"}
]
const whichDay = () =>{
switch(selectedCat){
case selectedCat === 'Monday':
setMon((aAlreadySelectedState)=>{return {
"morning": true,
...aAlreadySelectedState
}})
default:
break
}
}
return(
<Picker
mode="dropdown"
selectedValue={selectedCat}
onValueChange={(itemValue, itemIndex) => setSelected(itemValue) && whichDay()}
>
{category.map((item, index) => (
<Picker.Item
label={item.itemName}
value={item.itemName}
index={index}
/>))}
</Picker>
)
}

相关内容

  • 没有找到相关文章