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.

Not sure how to use 3rd party libraries with preact/compat

See original GitHub issue
  • Check if updating to the latest Preact version resolves the issue

Describe the bug So I’m trying to get rid of @types/react so that the code fully relies on preact and preact/compat. For some reason I get the following errors:

'ReactTooltip' cannot be used as a JSX component.
  Its instance type 'ReactTooltip' is not a valid JSX element.
    Type 'ReactTooltip' is missing the following properties from type 'Component<any, any>': state, props, context, setState, and 2 more.
JSX element class does not support attributes because it does not have a 'props' property.

I use vite as my bundler, which uses rollup. It starts fine without any issues with yarn start, seems like only typescript is upset with this behavior (which in turn breaks the bundling with yarn build).

It seems like most libraries work fine, except for these two. They are declared in node_modules like class SimpleBar extends React.Component<SimpleBar.Props>. Which should be fine as I’m using preact/compat? Maybe my tsconfig is somehow messed up? I’m currently working in this repo: https://github.com/BigWhaleLabs/seal-cred-frontend — but it’s a bit tedious to set it up so I provide it here just as a reference to my config files.

I’m sure I’m doing something wrong but I can’t put my finger on it. Are there any extra steps to achieve react/compat working with 3rd party components from npm except for modifying tsconfig as noted in here: https://preactjs.com/guide/v10/typescript?

To Reproduce Try using https://github.com/wwayne/react-tooltip or https://github.com/grsmto/simplebar.

Expected behavior No error should be shown?

Screenshots Screen Shot 2022-05-19 at 4 23 30 PM Screen Shot 2022-05-19 at 4 23 43 PM

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
rschristiancommented, May 20, 2022
1reaction
rschristiancommented, May 30, 2022

No, it was not.

Hopefully it creates symlinks, else, you might need to work out with its maintainers how to best go about this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What makes a React library require preact-compat?
Disclaimer: I work on preact. There are several APIs in react that are not needed for preact . But because existing third-party libraries...
Read more >
Fixing JSX types between Preact and React Libraries
How to fix JSX TypeScript errors due to incompatible types between Preact and imported React component libraries, especially for JSX.
Read more >
Upgrading from Preact 8.x
To make third-party React libraries work with Preact we ship a compatibility layer that can be imported via preact/compat . It was previously...
Read more >
When should I use preact compat?
Use preact/compat when you are including third-party libraries in your project that were originally written for React.
Read more >
Should Developers Use Third Party Libraries? | Scalable Path®
Sure, you'll still need to spend some time reading the library's ... So, using a proven third-party library should not endanger the overall ......
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