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

162
Visualizações
is there a way to add a new property to an existing endpoint link?

suppose I am getting information from a given endpoint and rendering the information to the page. the endpoint contains the person's name, address, age, and sport played. Now after I render all the information on the page using javascript and React, I want to ideally add a custom property called votes that will dynamically change and reflect on the site when a user voted for a player. This is how I added the new property.

const fetchPeople = async () => {
    try {
      const response = await fetch(url);
      const data = await response.json();
      const peopleWithVotes = data.map((person, index) => {
        return {
          ...person,
          votes: '0',
        };
      });

      setPeople(peopleWithVotes);
      console.log(people)
    } catch (error) {
      console.error(error);
    }
  };

this is how I have been trying to actually dynamically change the votes but don't know if I'm going in the right direction.

const handleClick = async (event) => {
        const votes = Number(event.target.dataset.votes);
        const requestOptions = {
            method: 'PATCH',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ votes: votes + 1 })
        };
        fetch(url, requestOptions)
            .then(response => response.json())
            .then((json) => console.log(json));
    

    }
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