Skip to content

Instantly share code, notes, and snippets.

@ryardley
Created October 28, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryardley/3f2b36b1cde0e0de1b714da1b09e0f2d to your computer and use it in GitHub Desktop.
Save ryardley/3f2b36b1cde0e0de1b714da1b09e0f2d to your computer and use it in GitHub Desktop.
An example of the old React mixin API
import React from 'react';
// numberBehaviour.js
const numberBehaviour = {
getInitialState() {
return {
newNumber: 1
}
},
setNewNumber(num) {
this.setState({
newNumber: num
})
}
}
// logger.js
const logger = {
logNumber(number) {
console.log(number)
}
}
// MyComponent.jsx
const MyComponent = React.createClass({
mixins: [
numberBehaviour,
logger
],
render() {
return <p>{this.state.newNumber}</p>
},
someStaticMethod(num) {
this.setNewNumber(num)
this.logNumber(num)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment