Skip to content

Instantly share code, notes, and snippets.

@JiDai
Created November 21, 2017 22:57
Show Gist options
  • Select an option

  • Save JiDai/a88054f0bc7c58ec279579ec1a98ca46 to your computer and use it in GitHub Desktop.

Select an option

Save JiDai/a88054f0bc7c58ec279579ec1a98ca46 to your computer and use it in GitHub Desktop.
Redux container (JetBrains)
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
/**
* Select props from Redux state.
* @param {Object} state Current state
*/
const mapStateToProps = state => ({
stateProp: state.stateProp,
});
/**
* Provide dispatch functions in props.
* @param {Function} dispatch Redux dispatch function
*/
const mapDispatchToProps = dispatch => ({
stateAction: () => dispatch({ type: 'action' }),
});
/**
* ${NAME} Component.
*/
export class ${NAME}Component extends Component {
/**
* Creates an instance of ${NAME}Component.
* @param {Object} props Component props
*/
constructor(props) {
super(props);
}
/**
* React lifecycle.
*/
render() {
return (
);
}
}
${NAME}Component.propTypes = {
stateProp: PropTypes.string,
stateAction: PropTypes.func,
};
/**
* ${NAME}Component connected.
*/
export default connect(mapStateToProps, mapDispatchToProps)(${NAME}Component);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment