Skip to content

Redux Snippets

Nick S. Plekhanov edited this page Sep 8, 2016 · 1 revision

Redux Core

Redux: Smart component (Container) — rdsc

import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; class ${1:MyComponent} extends Component { static propTypes = { $4 }; constructor(props) { super(props); this.state = {}; } render() { return ( ${5:<div>MyComponent</div>} ); } } const mapStateToProps = (state) => ({ $2 }); const mapDispatchToProps = (dispatch) => ({ $3 }); export default connect(mapStateToProps, mapDispatchToProps)(${1:MyComponent}); 

Redux: Reducer template — rdred

import * as types from '../constants/ActionTypes'; const initialState = { $2 }; export default function(state = initialState, action = {}) { switch (action.type) { case types.${3:ACTION}: return { $4 }; default: return state; } } 
Clone this wiki locally