Skip to content

Instantly share code, notes, and snippets.

@ereztdev
Last active April 8, 2018 10:03
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 ereztdev/4a08d38c7c8a8317e6abd291c52363e1 to your computer and use it in GitHub Desktop.
Save ereztdev/4a08d38c7c8a8317e6abd291c52363e1 to your computer and use it in GitHub Desktop.
PHPStorm / WEBStorm Live Template React Functional Component & React Redux Container Component (with mapStateToProps && mapDispatchToProps)
//isn't it tiring to write the same component but can't really copy paste for each place?
//Just use a code template as your boilerplate and change whatever you need, here is your starter:
//Functional component:
import React, { Component } from 'react';
class $NAME extends Component {
render() {
return (
<div>${END}</div>
);
}
}
export default $NAME;
//*****************************************//
//Redux Container Component:
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
// Import actions here!!
class $NAME extends React.Component {
constructor(props, context) {
super(props, context);
}
render() {
return (
<div>${END}</div>
);
}
}
${NAME}.propTypes = {
//myProp: PropTypes.string.isRequired
};
function mapStateToProps(state, ownProps) {
return {
state: state
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(actions, dispatch)
};
}
export default connect(mapStateToProps, mapDispatchToProps)($NAME);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment