You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @IceEnd! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.
IceEnd
changed the title
Babel define the method in the constructor
Why does Babel define the method in the constructor?
May 23, 2018
Your error is that you did not pass props to super() from your constructor's arguments. If you subclass React.Component and implement the constructor, you must pass the props (your first argument to constructor) to the super() call. This is how react defines their components class.
The getNotes is not a method, but a class instance field (stage 3) with an arrow function expression as a value. And instance fields are defined/initialized in the constructor when transpiled. Here is more information on the spec: https://github.com/tc39/proposal-class-fields
I use babel to compile the
react
code, and find that Babel defines the component methods in theconstructor
..babelrc
:component
:After compiling via
webpack
:Running in the browser gets an error:
Because there is no
super(props)
in theconstructor
.But in my code
constructor
does not need to useprops
.How to solve this problem?
The text was updated successfully, but these errors were encountered: