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

107
Visualizações
How show display all data using fetch method in React.js

I am Beginning in Programming. Now am trying to show All data in the display using the fetch data method. But Couldn't show this.

import { useEffect, useState } from "react";

const useProducts = () => {
    const [items, setItems] = useState([]);
    useEffect(() => {
        fetch("https://damp-island-69804.herokuapp.com/inventory")
            .then(res => res.json)
            .then(data => setItems(data))
    }, [])
    return [items, setItems];
}
export default useProducts;

What's the problem with this code? Please Help.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

please note res => res.json in your code should be res.json() as it is a function not property.

about 4 years ago · Juan Pablo Isaza Relatório

0

Refer This example : https://www.freecodecamp.org/news/fetch-data-react/

  1. Use resp.json() instead of resp.json
  2. Check resp.ok if not throw exception. Then set the exception message in another state variable.
  3. If loader used, show and hide accordingly by using the setter.
  4. Add try and catch accordingly And do clean up in the finally block.
about 4 years ago · Juan Pablo Isaza Relatório
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