Hacker News new | ask | show | jobs
by lukasm 3995 days ago
You have 3 options if you want mixin behaviour:

- Use old syntax or explicitly add mixin to prototype - Use composition. A bit annoying, because you have to make an extra class

    class OuterComponent extends React.Component {
      render() {
        return (
          <MixinComponent>
            <InnerComponent />
          </MixinComponent>
        );
      }
    }

    class InnerComponent extends React.Component{}
- wait for decorators (?)
1 comments

You can at least try decorators with babel using[1]

  $ babel --optional es7.decorators
or

  babel.transform("code", { optional: ["es7.decorators"] });
Here[2] is an article that describes how to use it for mixins

[1] https://babeljs.io/docs/usage/experimental

[2] http://raganwald.com/2015/06/26/decorators-in-es7.html