question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get totalPages prop in render method of Text component

See original GitHub issue

Describe the bug I am trying to display totalPages prop, but nothing is rendered. I am using version 2.0.0-beta.6 of react-pdf.

I tried to follow the example of the documentation. My code looks like this:

<Text render={({ pageNumber, totalPages }) => ${pageNumber} / ${totalPages}} />

To Reproduce

  1. Install latest version of react-pdf (2.0.0-beta.6)
  2. Try to display totalPage prop in a text

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • React-pdf version v2.0.0-beta.6

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

6reactions
seunggscommented, Jun 19, 2020

Finally figured it out - it was a styling issue.

You have to specify the minHeight property in order to show the actual content. Here’s an example:

<Text
  style={{
    fontSize: '12px',
    color: '#aaa',
    position: 'absolute',
    minHeight: '40px',
    bottom: '0px',
    left: '0px',
    right: '0px',
    textAlign: 'center',
  }}
  render={({ pageNumber, totalPages }) => (
    `${pageNumber}`
  )}
  fixed
/>
1reaction
brvnonascimentocommented, Jul 3, 2020

@brvnonascimento, I believe you’ll have to add the fixed attribute, too. In your example, you’ll probably also need to add a semi-colon ; to the end of your return line. If this doesn’t work, add more styling per previous examples. And if that doesn’t work, try logging to the console to see what’s going on there.

Thank you! It worked like a charm, with the “fixed” attribute it worked even without setting a minHeight. Before I was just setting fixed to the parent View. I ended up using an arrow function so the semicolon was unnecessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get the plain text from the render method from React ...
renderToString (this.renderParagraph()) console.log(plainText) // output in console: <p>I'm text from props of Text component!
Read more >
How to Build a Custom Pagination Component in React
We often work with web applications that need to fetch large amounts of data from a server through APIs and render it on...
Read more >
How To Build Custom Pagination with React | DigitalOcean
The Pagination component can take four special props as specified in the propTypes object. onPageChanged is a function called with data of the ......
Read more >
Render Props - React
The term “render prop” refers to a technique for sharing code between React components using a prop whose value is a function. A...
Read more >
Page wrapping - React-pdf
All you have to do is to pass a function to the render prop of the <Text /> or <View /> component. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found