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

116
Visualizações
Data is being added in the array but not showing on the UI until reload

I am posting new data to the backend. It is being sent successfully but the section where I fetched these data are not being updated until I press reload on the browser.

Here I am adding the code. Please let me know where am I making the problem? Thanks a lot.

//This is a custom hook where I am fetching data.
  const [products, setProducts] = useProductsHook();

  const handleAddProduct = () => {
    const newProduct = {
      name: productName,
      image: imageLink,
      desc: desc,
      price: +price,
      quantity: +quantity,
      supplier: supplierName,
    };
    axios.post("http://localhost:5000/api/products", newProduct).then((res) => {
      setProducts(products.concat(res.data));
      setProductName("");
      setImageLink("");
      setDesc("");
      setPrice("");
      setQuantity("");
      setSupplierName("");
    });
  };
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