How to add "parts" in this example The problem is that I can't add a new object
My current reducer:
case "ADD_PART": {
return {
...state,
exercise: state.exercise.map((items, id) =>
id === action.index ? items.parts[0].repeating : items
),
};
}
state before
{
"exercise": [
{
"id": "60e07e588a2f1946f895475f",
"name": "Wyciskanie sztangi",
"image": "uploads\\2021-07-03T15-12-24.173Z-test.gif",
"instruction": "Opierając tułów na ławce weź sztangielki",
"parts": [
{
"weight": 30,
"repeating": 10
}
],
"isOpen": true
}
]
}
State after run reducer it changes the object to me
{
"exercise": [
10
]
}
使用id
迭代器作为要从items
数组中选取的元素的索引。
id === action.index ? items[id].parts[0].repeating : items
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.