Skip to content

Show a better warning when accidentally returning from constructor #11381

@gaearon

Description

@gaearon

Based on a conversation with @vjeux:

I wrote

constructor(props) {
 return {
   something: false
 }
}

instead of

constructor(props) {
 super(props);
 this.state = {
   something: false
 }
}

and the error was super confusing, it told me that render is not defined on the component, which didn't make sense since I returned it!

We can fix this to show a different message if type has .prototype.isReactComponent but constructor() gave us something without a render method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions