PDFDownloadLink work only work when render but hit error when reload page
See original GitHub issueHi, I am trying to use PDFDownloadLink to create download pdf link in my react project. It works after render but after reload the page, it hit error and I don’t know why.
I am using react with next js and typescript.
Error is :
PDFDownloadLink is a web specific API. Or you're either using this component on Node, or your bundler is not loading react-pdf from the appropiate web build.
This is main template .tsx
import React from 'react'
import { Row, Col, Carousel } from 'antd'
import { PDFDownloadLink, Document, Page } from '@react-pdf/renderer'
import MyDocument from '../components/tour-itinerary-pdf'
export default class extends React.PureComponent<{tour: TcResponse<Tour>, cart: Cart}> {
render() {
const Print = () => (
<div>
<PDFDownloadLink document={<MyDocument />} fileName="somename.pdf">
{({ loading }) => (loading ? 'Loading document...' : 'Download now!')}
</PDFDownloadLink>
</div>
)
return(
<Row>
<Col>
{Print()}
</Col>
</Row>
)
}
}
This is component template
import React from 'react';
import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';
// Create styles
const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4'
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
}
});
// Create Document Component
class MyDocument extends React.Component{
render(){
return(
<Document>
<Page size="A4" style={styles.page}>
<View style={styles.section}>
<Text>Section #1</Text>
</View>
<View style={styles.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
)
}
}
export default MyDocument;
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (1 by maintainers)
Top Results From Across the Web
react-pdf: use PDFDownloadLink asynchronously without ...
Is there any way to make this operation asynchronous, so the rest of the application will continue to function while the PDF is...
Read more >Nextjs and React PDF Tutorial: WATCH THIS BEFORE ...
PDFViewer and PDFDownloadLink not working in browser? Error : ... work only work when render but hit error when reload page dispatcher.
Read more >How to Save State to LocalStorage & Persist on Refresh with ...
When we run our localStorage functions, we need to make sure that we're in the browser and we're outside of the React rendering...
Read more >How to send API call before page reload or close using ReactJS
The listener will only trigger the function before the page ... Components in React.js are nothing but a function that returns HTML tags....
Read more >Page wrapping - React-pdf
Fixed components. There is still another scenario we didn't talk about yet: what if you want to wrap pages but also be able...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m not using Nextjs but instead of doing the dynamic import, I use hooks in my component to prevent the PDFDownloadLink from SSRing
React PDF now ships with a
usePDF
hook permanently. You can use it and it works fine in Next.js