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.

Unexpected 'Editor cannot be used as a JSX component'

See original GitHub issue

Environment

    "@draft-js-plugins/editor": "^4.1.3",
    "@draft-js-plugins/static-toolbar": "^4.1.3",
    "draft-js": "^0.11.7",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "@types/draft-js": "^0.11.4",
    "@types/react": "^17.0.33",
    "@types/react-dom": "^17.0.9",

Description

I am trying to just set up a basic editor with static toolbar. However, whenever I try to import the Editor from the package I receive the following error:

JSX element class does not support attributes because it does not have a 'props' property.

'Editor' cannot be used as a JSX component.
  Its instance type 'PluginEditor' is not a valid JSX element.
    Type 'PluginEditor' is missing the following properties from type 'ElementClass': context, setState, forceUpdate, props, refs

Basically, it seems to not be recognizing the Editor at all. I haven’t seen any other related issues similar to this or found a great solution. The other plugins seem to work fine.

I have tried to following below by casting/type coercion, which seems to work for the most part. However then when I try to use plugins like anchor I am getting Invalid Hook Call errors.

import { default as _Editor } from '@draft-js-plugins/editor';
import { PluginEditorProps } from '@draft-js-plugins/editor';

const Editor = (_Editor as unknown) as React.FC<PluginEditorProps>;

<Editor editorState ... />

Screenshot from 2022-06-17 18-56-40

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
kdshah6593commented, Jul 14, 2022

Update: I tried to use the resolutions solution, but it did not seem to work for me; Of note, the Editor from draft-js directly does not produce the same error.

Temporary Solution is brute force type casting

import { default as _Editor } from '@draft-js-plugins/editor';
import { PluginEditorProps } from '@draft-js-plugins/editor';

const Editor = (_Editor as unknown) as React.FC<React.PropsWithChildren<PluginEditorProps>>;

However, I am running into issues with the Anchor Plugin, and not sure yet if that is a separate issue or related to this one.

0reactions
jonahcarneskogcommented, Oct 17, 2022
const Editor = dynamic<EditorProps>(
  () =>
    import("react-draft-wysiwyg").then(
      (mod) =>
        mod.Editor as unknown as React.FC<
          PropsWithChildren<{
            editorState: any;
            wrapperClassName: string;
            editorClassName: string;
            editorStateChange: any;
          }>
        >
    ),
  { ssr: false }
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

TS2786 'Component' cannot be used as a JSX component
Its instance type 'MessagesWidget' is not a valid JSX element. The types returned by 'render()' are incompatible between these types. Type ' ...
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 >
'switch' cannot be used as a jsx component - You.com
Its instance type 'Switch' is not a valid JSX element. The types returned by 'render()' are incompatible between these types. Type 'React.ReactNode' is...
Read more >
Strict Mode - React
In CSS, the display: contents attribute can be used if you don't want the node to be part of the layout. Detecting unexpected...
Read more >
[Solved] NPM package cannot be used as a JSX component
The NPM package cannot be used as a JSX component error occurs if you have installed multiple versions of @types/react package, ...
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