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.

'ReactPlayer' cannot be used as a JSX component

See original GitHub issue

Current Behavior

  • I receive the following error when trying to use Reac-player: JSX element class does not support attributes because it does not have a 'props' property.

Expected Behavior

I followed the instructions exactly using the following example code for the react-player component: <ReactPlayer url="https://www.youtube.com/watch?v=ysz5S6PUM-U" />

Steps to Reproduce

  1. Yarn add react-player
  2. Add 'import ReactPlayer from ‘react-player’ in your file
  3. Add <ReactPlayer url="https://www.youtube.com/watch?v=ysz5S6PUM-U" /> to your functional component

Environment

Other Information

I have a Typescript project. A similar issue was posted and for them deleting “flexbox-react” helped but I have no such dependency.

I have tried it in a sandbox, with react and typescript, and it works perfectly there so it must be something with my app, but I am not sure how to figure that out. I would appreciate any insight on this!

The screenshot below is of some warnings I received when installing the package.

Screenshot 2022-02-24 at 09 21 17

The error: Screenshot 2022-02-24 at 09 34 41

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
Mutesa-Cedriccommented, Jun 12, 2022

@MarianaK96 I think this will help as it worked for me:

import { default as _ReactPlayer } from 'react-player/lazy';
import { ReactPlayerProps } from "react-player/types/lib";
const ReactPlayer = _ReactPlayer as unknown as React.FC<ReactPlayerProps>;
Read more comments on GitHub >

github_iconTop Results From Across the Web

'ReactPlayer' cannot be used as a JSX component
'ReactPlayer' cannot be used as a JSX component. Its instance type 'ReactPlayer' is not a valid JSX element. The types returned by 'render()' ......
Read more >
cannot be used as a jsx component. its return type 'element
A component needs to return a single root element. You can use fragments to package an array of elements as a single element,...
Read more >
Component cannot be used as a JSX component in React
The error Component cannot be used as a JSX component occurs for multiple reasons, returning an array of JSX elements instead of a...
Read more >
Some components "cannot be used as a JSX component"
[Solved]-Some components "cannot be used as a JSX component"-Reactjs. Search. score:16. Accepted answer. I updated react & react-dom . npm i react@18 ...
Read more >
App can not be used as JSX component - react error - YouTube
Join this channel to get access to perks:https://www.youtube.com/channel/UCoSpmr2KNOxjwE_B9ynUmig/joinMy GearCamera ...
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