React React.createClass vs extends React.Component Mixins


Example

We can use mixins only with the React.createClass way.

React.createClass

In this version we can add mixins to components using the mixins property which takes an Array of available mixins. These then extend the component class.

import React from 'react';

var MyMixin = {
  doSomething() {

  }
};
const MyComponent = React.createClass({
  mixins: [MyMixin],
  handleClick() {
    this.doSomething(); // invoke mixin's method
  },
  render() {
    return (
      <button onClick={this.handleClick}>Do Something</button>
    );
  }
});

export default MyComponent;

React.Component

React mixins are not supported when using React components written in ES6. Moreover, they will not have support for ES6 classes in React. The reason is that they are considered harmful.