Flux container breaks class methods defined with class properties syntax
I have a component like this:
class MyComponent extends React.Component<Props, State> {
static getStores() {
return [MyStore];
}
static calculateState(prevState:State, props:Props):State {
return {};
}
doSomething = () => {
console.log('doSomething');
}
render() {
this.doSomething();
return null;
}
}
export default MyComponent;
When component renders, 'doSomething' is called correctly. However, when I change the export to this:
export default Container.create(MyComponent, {
pure: false,
withProps: true,
});
the doSomething method becomes undefined and I get Uncaught TypeError: this.doSomething is not a function
My babel config looks something like this:
{
"presets": ["@babel/preset-react"]
"plugins": [
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-proposal-class-properties"
]
}
Related deps with versions:
[email protected]
[email protected]
[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
@babel/[email protected]
[email protected]
[email protected]
This was not an issue up until yesterday (3/20/2020). I still haven't figured out what the issue is but have narrowed it down to the use of Container.create.
Anyone else running into this?
I had similar problem. It might be correlated to @babel/[email protected] update https://github.com/babel/babel/releases/tag/v7.9.0 It was released 20 Mar. My issue was with @babel/plugin-transform-classes dependency of @babel/preset-env Downgrading @babel/plugin-transform-classes by adding to package.json works for me for now.
"devDependencies": {
"@babel/plugin-transform-classes": "7.8.6",