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

232
Views
No se pueden mostrar los datos obtenidos en la página, React JS

No puedo mostrar los datos obtenidos en la página. Aquí estoy usando ReactJS para frontend y NodeJS para backend. Para almacenar datos, estoy usando blockchain (tejido Hyperledger)

Interfaz: ReactJS ,

 import React, { useState, useEffect } from "react"; import '../all.css'; import Axios from "axios"; const AllProduct = () => { const [products, setProducts] = useState([]); const fetchProducts = async () => { const { data } = await Axios.get( "http://localhost:8080/api/QueryAllProducts" ); console.log(data.response); setProducts(data.response); console.log(products); }; const display = () => { return (products || []).map(product => ( <tr key={product.id}> <th>{product.id}</th> <th>{product.name}</th> <th>{product.area}</th> <th>{product.ownerName}</th> <th>{product.cost}</th> </tr> ) ); } useEffect(() => { fetchProducts(); }, []); return ( <div> <table> <thead> <tr> <th>ID</th> <th>Name</th> <th>Area</th> <th>Owner Name</th> <th>Cost</th> </tr> </thead> <tbody> {display()} </tbody> </table> </div> ) } export default AllProduct;

No puedo mostrarlo en la página. En frontend he usado ReactJS y en backend he usado nodeJS, Hyperledger Fabric y base de datos CouchDB

captura de pantalla actualizada

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

0

Siguiendo los cambios necesarios en su código

  1. display es una función, por lo que debe llamarla como display()

  2. coloca display() dentro de <tbody>

  3. accesorios key al usar la función map()

     const display = () => { if(products.length===0) return null; return products.map(product => ( <tr key={product.id}> <th>{product.id}</th> <th>{product.name}</th> <th>{product.area}</th> <th>{product.ownerName}</th> <th>{product.cost}</th> </tr> ) ); }
  4.  setProducts(JSON.parse(data.response));
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!