plangrid / react-file-viewer

MIT License
517 stars 336 forks source link

"Deprecated API usage: getDocument" with Functioning Component #124

Open AdamWhitehurst opened 4 years ago

AdamWhitehurst commented 4 years ago

My team currently has a Component that implements <FileViewer> that works, but our tests warn us that:

console.log node_modules/react-file-viewer/dist/index.js:11
      Deprecated API usage: getDocument is called with pdfDataRangeTransport, passwordCallback or progressCallback argument

Would love to see this updated as react-file-viewer a good library.

Similar issue (but this appears to be a non-functioning component): https://github.com/plangrid/react-file-viewer/issues/83

Relevant information on updating package: https://github.com/mozilla/pdf.js/issues/8538 https://github.com/mozilla/pdf.js/commit/5135aa9becc15a79a565ddf33452e2351196bd5b#diff-dd42e9b2d2a652b8e312efa567698aa6

It appears the call to getDocument simply needs to be updated to the simplified parameters, with callbacks being set with onProgress, onPassword, etc.

startgirl commented 1 month ago

Maybe I solved this problem by putting FileViewer in the mod and getting an error: Depreciated API usage: getDocument is called with pdfDataRangeTransport, passwordCallback or progressCallback argument, Then I only showed FileViewer 3 seconds after the modal display, and the file could be displayed normally

<Modal title={'预览' + get(materialInfo, 'name')} visible={true} onCancel={() => { setVisible(false); props.closeFun() }} footer={null} width={1300} bodyStyle={{ padding: 0, overflow: 'auto' }} > <div style={{ height: 450,textAlign:'center' }} className='pdf'> { getType() == 'pdf' &&materialInfo&&show&& <FileViewer fileType='pdf' filePath={get(materialInfo, 'file_url')} onError={(err)=>{console.log(err)}} /> } </Modal> setTimeout(() => { setShow(true) }, 3000);