Unexpected 'Editor cannot be used as a JSX component'
See original GitHub issueEnvironment
"@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 ... />
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update: I tried to use the
resolutions
solution, but it did not seem to work for me; Of note, theEditor
fromdraft-js
directly does not produce the same error.Temporary Solution is brute force type casting
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.