#486·flux

Flux container breaks class methods defined with class properties syntax

Author: MarkPareCreated Mar 22, 2020Updated Jun 4, 2020

I have a component like this:

bash
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:

bash
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:

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?