Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Cómo mostrar todos los datos usando el método de búsqueda en React.js

Soy Principiante en Programación. Ahora estoy tratando de mostrar todos los datos en la pantalla usando el método de obtención de datos. Pero no se pudo mostrar esto.

 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;

¿Cuál es el problema con este código? Por favor ayuda.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

tenga en cuenta que res => res.json en su código debe ser res.json() ya que es una función, no una propiedad.

about 4 years ago · Juan Pablo Isaza Report

0

Consulte este ejemplo: https://www.freecodecamp.org/news/fetch-data-react/

  1. Use resp.json() en lugar de resp.json
  2. Marque resp.ok si no arroja una excepción. Luego establezca el mensaje de excepción en otra variable de estado.
  3. Si se usa el cargador, muestre y oculte en consecuencia usando el setter.
  4. Agregue try and catch en consecuencia Y limpie en el bloque finalmente.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!