react-pdf
react-pdf copied to clipboard
stream.push() after EOF
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.
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>
....
....
...
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.