I'm searching data from db and results displays in table form.Then user can download pdf of any record. I'm using @react-pdf/renderer library to generate pdf but problem with this library is that its generate pdf of all results once. therefore system hangs due to large number of result. I need a library which only generate pdf to user specific record not all at once.
below is example
import React, {useState} from 'react';
import { PDFDownloadLink, Document, Page,Text } from '@react-pdf/renderer'
const _data = [
{
name: 'Bi'
},
{
name: 'Ars'
},
{
name: 'Saee'
}
]
const MyDoc = ({data}) => (
<Document>
<Page>
<Text>{data.name}</Text>
</Page>
</Document>
)
const App = () => {
const [data, setData] = useState(_data);
const clickHandler = (key) => {
return (
<PDFDownloadLink document={<MyDoc data={data[key]} />} fileName="somename.pdf">
{({ blob, url, loading, error }) => (loading ? 'Loading document...' : url)}
</PDFDownloadLink>
)
}
return (
<div>
<table>
<thead>
<tr>
<th>Sr</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{data.map((item, i) => {
return (
<tr key={i} onClick={() => clickHandler(i)}>
<td>{i}</td>
<td>{item.name}</td>
</tr>
);
})}
</tbody>
</table>
</div>
)
}
export default App;