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

974
Views
Error de ReactJS react-pdf "Error al cargar el archivo PDF". en algunos intentos

Creé una aplicación react js con create-react-app y estoy probando react-pdf para ver archivos pdf. el problema que tengo es que mi código a veces funciona ya veces no. cuando cargo la aplicación por primera vez, el pdf siempre se carga bien, pero si visito otros enlaces/URL en el sitio y luego navego a la página con el pdf, es probable que el pdf no se cargue en algunos intentos con un error "Error al cargar Archivo PDF".

si el error se parece a la imagen de abajo ingrese la descripción de la imagen aquí

si tiene éxito, se ve como la imagen de abajo ingrese la descripción de la imagen aquí

así es como lo he implementado

importaciones

 import { Document, Page, pdfjs } from 'react-pdf/dist/esm/entry.webpack'; import { useState } from 'react'; import 'react-pdf/dist/esm/Page/AnnotationLayer.css';

implementación de código

 function ReactPDF() { const imageKitURL = ' https://ik.imagekit.io/kwmvfjr0r'; const pdf = `${imageKitURL}/test_files/file-example_PDF_1MB.pdf`; const [numPages, setNumPages] = useState(null); const [pageNumber, setPageNumber] = useState(1); function onDocumentLoadSuccess({ numPages }) { setNumPages(numPages); setPageNumber(1); } function changePage(offset) { setPageNumber((prevPageNumber) => prevPageNumber + offset); } function previousPage() { changePage(-1); } function nextPage() { changePage(1); } return ( <> <div> <p> Page {pageNumber || (numPages ? 1 : '--')} of {numPages || '--'} </p> <button type="button" disabled={pageNumber <= 1} onClick={previousPage}> Previous </button> <button type="button" disabled={pageNumber >= numPages} onClick={nextPage}> Next </button> </div> {/* eslint-disable-next-line react/jsx-no-bind */} <Document file={pdf} onLoadSuccess={onDocumentLoadSuccess}> <Page pageNumber={pageNumber} /> </Document> </> ); }

espero que la pregunta sea lo suficientemente detallada para explicar la situación

about 4 years ago · Juan Pablo Isaza
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!