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.

Types are incompatible with React 18

See original GitHub issue

Describe the bug Using the package in react 18 is giving the error of children not mentioned in the props

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

  1. Create a Sample File using React 18
  2. Try to Run the app
  3. See error

'(props: DocumentProps | Readonly<DocumentProps>): Document', gave the following error. Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Document> & Readonly<DocumentProps>'. Overload 2 of 2, '(props: DocumentProps, context: any): Document', gave the following error. Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Document> & Readonly<DocumentProps>'.ts(2769) @diegomura

I belive in react 18 you need to explicitly define the children props https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

35reactions
RiJungcommented, Apr 11, 2022

if you want to use React18 , i use my little dirty helper this work, renaming helps to trick Typescript

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

// rename helper for react18 overload
const MyDocument: any = Document
const MyPage: any = Page

// example code
const PDF= () => (
  <MyDocument>
    <MyPage="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </MyPage>
  </MyDocument>

26reactions
Rafael805commented, May 26, 2022

Does anyone know when it will be compatible with React 18?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: React 18 types broken since the type release a ... - GitHub
This almost guarantees that any project using @types/react versions 17 and 18 will break. In my case it's because I have multiple projects ......
Read more >
React v18.0 – React Blog
In this post, we'll give an overview of what's new in React 18, ... but it's effective at preventing the most common types...
Read more >
MUI installation doesn't work with React 18 - Stack Overflow
Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and ...
Read more >
React 18 is not compatible with Fluent UI and how to work ...
The reason in both cases for the error is that once React 18 is installed, Fluent UI will not install since it requires...
Read more >
Library authors should revise typings to support React 18
You could write function components without children , no problem. React offered a FC type that defined a function component with children ....
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