I'm making my first React app, and I'm using json-server as a fake backend. It's a workout planner app, and I'm trying to figure out how to add exercises to each day. What I have is the feature to add new exercises, and now I'm trying to add these exercises to each date.
"dates": [
{
"id": 22102021,
"exercises": [
{
"id": 0,
"name": "Squats",
"amount": "3x10"
}
]
},
{
"id": 23102021,
"exercises": [
{
"id": 0,
"name": "Bicep curls",
"amount": "3x8"
}
]
}]
This is the dates array that I have in my db.json, the date is the id, and I'm trying to access the exercises array to add more exercises.
await fetch(`http://localhost:8000/dates?id=${ID}`, {
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify(exercise),
});
This is a part of the function that adds the exercises, the fetch function is where I'm confused. How do I access the exercises array inside the object? I suppose I have to write the id of the date, but if I add an exercise now, it looks like this.
"dates": [
{
"id": 22102021,
"exercises": [
{
"id": 0,
"name": "Squats",
"amount": "3x10"
}
]
},
{
"id": 23102021,
"exercises": [
{
"id": 0,
"name": "Bicep curls",
"amount": "3x8"
}
]
},
{
"name": "deadlifts",
"amount": "3x12",
"id": 23102022
}]
EDIT: found an almost exact unanswered problem here.