Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
JSON Server routing/filtering

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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda