Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda