react-modal: "Warning: React.createElement: type is invalid"
See original GitHub issueSummary:
I am going to popup a modal. I am using Visual Studio 2017, typescript 2.8.1 and Google Chrome. But I have got some errors.
Errors
Warning: React.createElement: type is invalid – expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.
Check the render method of `UserList`.
in UserList (created by Connect(UserList))
in Connect(UserList) (created by Route)
in Route
in main
in div
in Router (created by ConnectedRouter)
in ConnectedRouter
in Provider
printWarning @ warning.js:33
warning @ warning.js:57
createElementWithValidation @ react.development.js:1296
render @ UserList.tsx:133
finishClassComponent @ react-dom.development.js:8389
updateClassComponent @ react-dom.development.js:8357
beginWork @ react-dom.development.js:8982
performUnitOfWork @ react-dom.development.js:11814
workLoop @ react-dom.development.js:11843
renderRoot @ react-dom.development.js:11874
performWorkOnRoot @ react-dom.development.js:12449
performWork @ react-dom.development.js:12370
performSyncWork @ react-dom.development.js:12347
interactiveUpdates @ react-dom.development.js:12597
interactiveUpdates @ react-dom.development.js:1958
dispatchInteractiveEvent @ react-dom.development.js:4259
Code:
import * as React from 'react'
import { Link } from 'react-router-dom'
import { ContextMenu, MenuItem, ContextMenuTrigger } from "react-contextmenu";
import { Modal } from 'react-modal';
import { ToastContainer, toast } from 'react-toastify';
export interface IUserListProps {
users: Array<any>
error: string
dispatchBlacklistUser: ((userNickname: string) => void)
dispatchActivateConversation: ((roomGuid: string) => void)
}
export interface IUserListState {
userNickname: string
openingAddFriend: boolean
}
export class UserList extends React.Component<IUserListProps, IUserListState> {
constructor(props) {
super(props);
this.state = {
userNickname: '',
openingAddFriend: false
};
this.handleClick = this.handleClick.bind(this);
}
handleClick = (e, data) => {
if (data.action === 'AddFriend') {
this.setState({ openingAddFriend: true });
} else if (data.action === 'SendMessage') {
} else if (data.action === 'ActivatePrivateMessage') {
this.props.dispatchActivateConversation("roomGuid");
} else if (data.action === 'AddBlacklist') {
if (confirm("blacklist?")) {
this.props.dispatchBlacklistUser(data.nickname);
}
}
}
closeAddFriend() {
this.setState({ openingAddFriend: false });
}
render() {
const { openingAddFriend } = this.state;
return (
<div>
<div className="chat-userlist-tabcontainer">
<Link to="/users">
<div className="chat-userlist-tab chat-userlist-all active">
<i className="fa fa-users userlist-tab-usericon"></i>
<div className="userlist-tab-name">Participants</div>
</div>
</Link>
<Link to="/friends">
<div className="chat-userlist-tab chat-userlist-white">
<i className="fa fa-user userlist-tab-usericon"></i>
<div className="userlist-tab-name">My Friends</div>
</div>
</Link>
<Link to="/blacklist">
<div className="chat-userlist-tab chat-userlist-black">
<i className="fa fa-ban userlist-tab-usericon"></i>
<div className="userlist-tab-name">Blacklist</div>
</div>
</Link>
<div className="clearfix"></div>
</div>
<div>
{this.props.users.map((item, index) =>
<div className="chat-userlist-container" key="{ index }">
<ContextMenuTrigger id="userlist-contextmenu">
<div>{ item.NickName }</div>
</ContextMenuTrigger>
<ContextMenu id="userlist-contextmenu">
<MenuItem onClick={ this.handleClick } data={{ accountId: item.AccountId, action: 'AddFriend' }}>
<i className='fa fa-user'></i> Add Friend
</MenuItem>
<MenuItem onClick={ this.handleClick } data={{ accountId: item.AccountId, action: 'SendMessage' }}>
<i className='fa fa-envelope'></i> Send Message
</MenuItem>
<MenuItem onClick={ this.handleClick } data={{ accountId: item.AccountId, action: 'ActivatePrivateMessage' }}>
<i className='fa fa-comments'></i> Private Message
</MenuItem>
<MenuItem onClick={ this.handleClick } data={{ accountId: item.AccountId, action: 'AddBlacklist' }}>
<i className='fa fa-ban'></i> Add Blacklist
</MenuItem>
</ContextMenu>
</div>
)}
</div>
<div>
<Modal isOpen="{ this.state.openingAddFriend }" contentLabel="Confirmation" center>
<div>Are you sure to add this person to friend list?</div>
</Modal>
</div>
<ToastContainer />
</div>
);
}
}
Additional notes:
Error occured in <Modal isOpen="{ this.state.openingAddFriend }" contentLabel="Confirmation" center>
If possible, please let me know this bug reason.
Otherwise please let me know the alternative of react-modal.
Thank you.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
React.createElement: type is invalid -- expected a string
Most of the time this is due to an incorrect export/import. Common error: // File: LeComponent.js export class LeComponent extends React.Component { ....
Read more >Error React createElement type is invalid expected a string for ...
js. I get the following error. React.createElement: type is invalid -- expected a string (for built-in components) or a class/function ...
Read more >React.createElement: type is invalid — expected a string
This somewhat cryptic error usually has a simple solution. More often than note a quick notation fix can solve the issue. What's the...
Read more >(React) Element type is invalid, expected a string (for built in ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >react-modal documentation
The following is an example of using react-modal specifying all the possible props and ... import ReactModal from 'react-modal'; <ReactModal isOpen={ false ......
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 Free
Top 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
My file extension is tsx, not jsx. These solutions are not working.
But I found other solution.
Please let me know whether this code is correct.
Hi @dragonball9816, you can check if all the imported names are valid (none should be
undefined
).If you get a undefined value, you can check if the names exported by a library are exported as
default
or not. Example: