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

390
Views
Sorprendentemente no puedo encontrar una solución a esto. react-csv se descarga automáticamente al servidor en lugar de la elección del usuario

así que estoy generando una factura y estoy usando el paquete react-csv para convertir mis datos de graphql en un archivo csv. el problema es que no quiero que el usuario seleccione una ubicación localmente para descargar (comportamiento listo para usar). Debe guardarse automáticamente en un directorio codificado en el servidor. ¿¿¿Cualquiera???

 <CSVLink onClick={generateInvoice} className="mt-1 inline-block align-middle w-full inline-flex justify-center py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-400 hover:bg-blue-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" filename={csvfilename} data={csvinvoiceForDownload} headers={headers}> Create Invoice </CSVLink>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No necesita reaccionar-csv, es para renderizar datos ...
Puede usar, por ejemplo, PapaParse https://www.papaparse.com/docs#json-to-csv para convertir su objeto graphQL en scv, que puede enviar con fetch o axios a su servidor...

 // With implicit header row // (keys of first object populate header row) var csv = Papa.unparse([ { "Column 1": "foo", "Column 2": "bar" }, { "Column 1": "abc", "Column 2": "def" } ]);

También puedes usar js:

 const items = json3.items const replacer = (key, value) => value === null ? '' : value // specify how you want to handle null values here const header = Object.keys(items[0]) const csv = [ header.join(','), // header row first ...items.map(row => header.map(fieldName => JSON.stringify(row[fieldName], replacer)).join(',')) ].join('\r\n') console.log(csv)

(ejemplo encontrado en SO: Cómo convertir JSON a formato CSV y almacenar en una variable )

ahí puedes encontrar más opciones...

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!