react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

stream.push() after EOF

Open DavidMPRocha opened this issue 6 years ago • 1 comments

Hi, I'm new to react and I have a problem using react-pdf, I'm using “BlobProvider” but it gives me an error and I've already researched a lot and I can't solve it. I'll leave a very simple code of what I'm doing, I hope you can solve it. And I'm sorry for my weak English.

Link image error

PDF PAGE

import React from 'react'
import { BlobProvider, Document, Page, Text } from '@react-pdf/renderer'

const MyDoc = ({ value }) => (
  <Document>
    <Page>
      <Text>{value}</Text>
    </Page>
  </Document>
)

export class App extends React.Component {
    state = { value: 'text' }
  
    render() {
        return (
            <div style={{ height: '100%' }}>
                <BlobProvider document={MyDoc({ value: this.state.value })}>
                    {({ url }) => <iframe src={url} style={{ width: '100%', height: '100%' }} />}
                </BlobProvider>
            </div>
        )
    }
}

MY PAGE

import React, { useState, useEffect } from 'react';
import { App } from './pdf.js';

....
....
....

<div>
    <App />
</div>


....
....
...

DavidMPRocha avatar Apr 15 '20 13:04 DavidMPRocha

You can wrap pdf generating component with React.memo() if it's a pure component. It helps to stop rendering the component if same props are found. In your above demo,

you can use

const MyDoc = ({value}) => (..... ); const MemoizedMyDoc = React.memo(MyDoc)

And then use MemoizedMyDoc in App component.

pandeysabin avatar Apr 16 '20 10:04 pandeysabin