Skip to content

Instantly share code, notes, and snippets.

@tecsyscom
Last active April 14, 2017 14:59
Show Gist options
  • Save tecsyscom/44165a6c0f1726ecebf2fff05803ac1e to your computer and use it in GitHub Desktop.
Save tecsyscom/44165a6c0f1726ecebf2fff05803ac1e to your computer and use it in GitHub Desktop.
no ES6
import React from 'react';
var SomeMixin = {
doSomething() {
}
};
const App = React.createClass({
getInitialState: function() {
return {count: this.props.initialCount};
},
propTypes: {
},
getDefaultProps() {
return {
name: 'Mary'
};
},
mixins: [SomeMixin],
handleClick() {
this.doSomething(); // use mixin
},
render() {
return (
<div onClick={this.handleClick}></div>
);
}
});
function mapStateToProps(state) {
console.log(state);
return {
todos: state.todos
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(TodoActions, dispatch)
};
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(App);
@tecsyscom
Copy link
Author

You can do this with ES7 object spread proposal:

bindActionCreators({ ...SomeActions, ...OtherActions }, dispatch)
or (vanilla ES6, needs Object.assign polyfill or Babel plugin)

bindActionCreators(Object.assign({}, SomeActions, OtherActions), dispatch)
or (ES5, assumes lodash)

var assign = require('lodash/object/assign');

bindActionCreators(assign({}, SomeActions, OtherActions), dispatch)

@tecsyscom
Copy link
Author

ReactDOM.render(
element,
document.getElementById('root')
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment