
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
react-es6-classy-mixins
Advanced tools
Mixer for ES6 React classes
I love ES6 classes, but when I started to use ES6 with React I was missing mixin ability.
I needed simple yet easy to apply and (mostly) compatible with old plain object mixins (as I had many mixins in my library) way of applying mixins, but with nice ES6 syntax.
I said "mostly" because React seals props property in classes thus preventing it's mutation. And I really don't want to fight against that, it's cool.
See the Pen React ES6 classes with mixins by Piotr "Hitori" Bosak (@HitoriSensei) on CodePen.
npm install react-es6-classy-mixins
Mixins stay the same plain objects as of before ES6 class syntax, eg.
var MixinA = {
getInitialState: function () {
return {
mixinA: 1
}
}
}
var MixinB = {
getInitialState: function () {
return {
mixinB: false
}
},
activateMixinB: function() {
this.setState({mixinB: true})
},
deactivateMixinB: function() {
this.setState({mixinB: false})
},
componentDidMount: function(){
debuglog.innerHTML += "MixinB.componentDidMount()"
},
x: function(){
return 1
}
}
var MixinC = {
componentDidMount: function(){
debuglog.innerHTML += "<br/>MixinC.componentDidMount()"
},
x: function(){
return 2
}
}
var MixinD = {
componentDidMount: function(){
debuglog.innerHTML += "<br/>MixinD.componentDidMount()"
},
getInitialState: function () {
return {
mixinB: true
}
},
x: function(){
return 4
}
}
instead of
class YourComponent extends BaseClass{...}
write
import ReactComponentWithMixins from "react-es6-classy-mixins"
class YourComponent extends ReactComponentWithMixins(mixins..., BaseClass){...}
for example
import ReactComponentWithMixins from "react-es6-classy-mixins"
class YourComponent extends ReactComponentWithMixins(MixinC, MixinB, MixinA, React.Component){...}
Mixins are executed from left to right
If there are more than one mixin with method of the same name returning a value (like this.x()) , only leftmost value will be returned but ALL methods will be executed in left to right order!
import ReactComponentWithMixins from "react-es6-classy-mixins"
class WithMixins extends ReactComponentWithMixins(MixinC, MixinB, MixinA, React.Component){...}
/* Order of execution (left to right): */
Base.componentDidMount()
MixinC.componentDidMount()
MixinB.componentDidMount()
import ReactComponentWithMixins from "react-es6-classy-mixins"
class WithExtendAndMixins extends ReactComponentWithMixins(MixinD, MixinB, WithMixins){...}
/* Order of execution (left to right): */
Extended.componentDidMount()
MixinD.componentDidMount()
MixinB.componentDidMount()
Base.componentDidMount()
MixinC.componentDidMount()
MixinB.componentDidMount()
note that MixinB.componentDidMount() is executed twice
FAQs
React ES6 components with mixins
We found that react-es6-classy-mixins demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.