-
Notifications
You must be signed in to change notification settings - Fork 50.2k
Closed
Description
The error above has caught me twice now, and it's hard to debug. Perhaps an extra check could make this less hard to debug.
This is the location where the error happens:
function instantiateReactComponent(element, parentCompositeType) {
var instance;
if ("production" !== process.env.NODE_ENV) {
("production" !== process.env.NODE_ENV ? warning(
element && (typeof element.type === 'function' ||
typeof element.type === 'string'),
'Only functions or strings can be mounted as React components.'
) : null);
// Resolve mock instances
// ERROR OCCURS HERE BECAUSE type IS UNDEFINED:
if (element.type._mockedReactClassConstructor) {
// If this is a mocked class, we treat the legacy factory as if it was the
// class constructor for future proofing unit tests. Because this mightThe cause is always using an undefined variable in a JSX tag, like so:
var OtherComponent=undefined;
mycomp.render = function() {
return (<OtherComponent/>);
}The reason I get this error is because I often forget that I export OtherComponent directly using
module.exports=React.createClass(...);and then I import it like so
var otherComponent = require("other-component");
var OtherComponent = otherComponent.OtherComponent;which is wrong but not obviously so.
It would help very much to have an assertion on the first parameter of React.createElement() right away when it is called.
Metadata
Metadata
Assignees
Labels
No labels