React-pdf: ReactPDF.render is not a function

Created on 10 Aug 2018  路  8Comments  路  Source: diegomura/react-pdf

OS:
macOS High Sierra v.10.13.6

React-pdf version:
1.0.0-alpha.14

Description:
When I am trying to render the ReactPDF in the componentWillMount I am getting the error __WEBPACK_IMPORTED_MODULE_1__react_pdf_renderer__.f.render is not a function. Below is the full code snippet. My goal is to download a version of the PDF on the mounting of a page and show a loading screen to the user. Please let me know if anyone has faced this issue or knows the solution! Cheers!

import React, { Component } from 'react'
import ReactPDF, { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer'

import autobind from 'react-autobind'

class Container extends Component {
  constructor (props) {
    super(props)

    this.state = {
      demographics: [],
      isDataLoaded: false,
    }

    autobind(this)
  }

  componentWillMount () {
    ReactPDF.render(<MyDocument />, `${__dirname}/example.pdf`)
  }

  render () {
    return (
      <Main />
    )
  }
}

// Create styles
const styles = StyleSheet.create({
  page: {
    flexDirection: 'row',
    backgroundColor: '#E4E4E4',
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1,
  }
})

// Create Document Component
const MyDocument = () => (
  <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>
)

const Main = () => (
  <div>loading pdf</div>
)

export default Container

Most helpful comment

Hey.
If you read the README you will see that ReactPDF.render is the mounter function for generating documents using Node (server-side). You鈥檙e using the lib in a web environment.
There鈥檚 an open issue about generating documents on the fly. It鈥檚 not something completely solved, but please refer to it

All 8 comments

Hey.
If you read the README you will see that ReactPDF.render is the mounter function for generating documents using Node (server-side). You鈥檙e using the lib in a web environment.
There鈥檚 an open issue about generating documents on the fly. It鈥檚 not something completely solved, but please refer to it

@diegomura
README says that ReactPDF.render only "Save in a file".
I used resume example and replace react-pdf.es.jsto @react-pdf/renderer.
And I used ReactDOM.render(<MyDocument />, document.getElementById('root')); for client side.

However it shows just text..

2018-11-30 15 18 49

Hey.
If you read the README you will see that ReactPDF.render is the mounter function for generating documents using Node (server-side). You鈥檙e using the lib in a web environment.
There鈥檚 an open issue about generating documents on the fly. It鈥檚 not something completely solved, but please refer to it

Any updates on this issue?

Yep. Generating docs on the fly has been around for awhile now. Check https://react-pdf.org/advanced#on-the-fly-rendering

Yep. Generating docs on the fly has been around for awhile now. Check https://react-pdf.org/advanced#on-the-fly-rendering

There is some issue when I apply to my react web
import { PDFDownloadLink, Document, Page } from '@react-pdf/renderer'
const MyDoc = () => (<Document><Page>ABC</Page></Document>)
const App = () => (<div><PDFDownloadLink document={<MyDoc />} fileName="somename.pdf">{({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')}</PDFDownloadLink</div>)

then inside the react export class:

public render(): React.ReactElement<IJsomProps> {<div>Export</div><div><PDFDownloadLink document={<MyDoc />} fileName="somename.pdf"> {({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')} </PDFDownloadLink></div>}

it gives the error
image

What issue?

What issue?

I got the error of 'getCurrentStack' of undefined. Please see the above screen capture. Thanks!

Open a new issue with this. Not sure why you posted this here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

serkyen picture serkyen  路  4Comments

kishaningithub picture kishaningithub  路  4Comments

mdodge-ecgrow picture mdodge-ecgrow  路  3Comments

GasimGasimzada picture GasimGasimzada  路  3Comments

brandly picture brandly  路  3Comments