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

144
Views
¿Cómo recuperar datos de búsqueda de un JSON?

En un componente React

 import React from 'react'; export default function Customers (props) { const [customers, setCustomers] = React.useState([]); React.useEffect(() => { fetch("/data.json").then(response => response.json()) .then(data => { setCustomers([data]) }) }, []); return ( <div id='Customers'> {customers.map(c => c.name)} </div> )

¿Cómo puedo mostrar solo los nombres de los clientes de un archivo en el directorio público llamado data.json?

 { "customers": [ { "id": 542, "name": "E" }, { "id": 354, "name": "V" }, { "id": 54534 "name": "A" } , { "id": 33, "name": "K" } ], "packages": [ { "id": 3643453453453, "weight": 6343 }, { "id": 453453, "weight": 4534534534 } ] }

Intenté usar clientes["clientes"] o clientes.clientes pero nada funcionó...

Gracias.

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

0

Creo que deberías cambiar el React.useEffect a esto

 React.useEffect(() => { fetch("/data.json") .then(response => response.json()) .then(data => { setCustomers(data.customers) //this is where I made the change }); }, []);
about 4 years ago · Juan Pablo Isaza Report

0

import React from 'react'; export default function Customers (props) { const [data, setData] = React.useState({}); React.useEffect(() => { fetch("/data.json").then(response => response.json()) .then(res => { setCustomers(res) }) }, []); return ( <div id='Customers'> {data && data.customers ? data.customers.map(c => c.name) : null} </div> )
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!