Mixins

suggest change

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


React.createClass vs. extends React.Component:
*Mixins

Table Of Contents