mikecousins/react-pdf-js

TypeError: canvasEl is undefined

Closed this issue · 4 comments

gcjbr commented

I followed the code on the front page and got this error when running:

import React, { useState, useRef } from 'react';
import { usePdf } from '@mikecousins/react-pdf';

export default () => {
  const [page, setPage] = useState(1);
  const canvasRef = useRef(null);
  const { pdfDocument, pdfPage } = usePdf({
    file: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf',
    page,
    canvasRef,
  });

  return (
    <div>
      {!pdfDocument && <span>Loading...</span>}
      <canvas ref={canvasRef} />
      {Boolean(pdfDocument && pdfDocument.numPages) && (
        <nav>
          <ul className="pager">
            <li className="previous">
              <button disabled={page === 1} onClick={() => setPage(page - 1)}>
                Previous
              </button>
            </li>
            <li className="next">
              <button
                disabled={page === pdfDocument.numPages}
                onClick={() => setPage(page + 1)}
              >
                Next
              </button>
            </li>
          </ul>
        </nav>
      )}
    </div>
  );
};

@mikecousins, hi, could you publish latest changes, please?

@mikecousins, hi, could you publish latest changes, please?

The latest code is published. I'll look into this. Also maybe ping @ksocha

I checked the above code and it works with the 5.5.0 version.

Okay let's close this then for now. Please let me know if it's resolved with the latest version.