From b950e761b284b88770549e9d14dcaeeefed3040a Mon Sep 17 00:00:00 2001 From: Yong Su Date: Sun, 22 May 2016 13:58:30 -0700 Subject: [PATCH] Update README.md --- README.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 322f7bc..abb72a0 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ Feeling bored with typing or even copying React codes to write React components The snippets follow JavaScript ES6 syntax, we don't use the old `React.createClass({...})` anymore, we write class component and functional component. Also we provide snippets to quickly write React Lifecycle functions (e.g. `componentDidMount`). +## Latest Updates (May 22, 2016) ## + * Reorganized folder structure and grouped snippets to: React, Redux and Test + * Added Redux related snippets to help you write actions, reducers and redux components faster + * Added `` snippet + ## Examples ## **ES6 Class Component**
![rcc](screenshots/rcc.gif)
@@ -16,6 +21,8 @@ The snippets follow JavaScript ES6 syntax, we don't use the old `React.createCla ## Snippets ## +### React ### + **ES6 Class Component** `rcc + ` ```javascript import React, { Component, PropTypes } from 'react'; @@ -197,6 +204,81 @@ shouldComponentUpdate(nextProps, nextState) { } ``` +### Redux ### + +**Redux Component** `rrc + ` +```javascript +import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; +import { + ${2:action} as ${2:action}Action, +} from '${3:path}'; + +const mapDispatchToProps = (dispatch) => { + return { + ${2:action}: () => { + dispatch(${2:action}Action()); + }, + }; +}; + +const mapStateToProps = ({ state }) => ({ + ${4:prop}: state.${4:prop} +}); + +export class ${1:Component} extends Component { + render() { + const { + ${2:action} + } = this.props; + + return ( + ${0} + ); + } +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(${1:Component}); +``` + +**Redux Action** `rra + ` +```javascript +export const ${1:action} = (${2:payload}) => ({ + type: ${3:type}, + ${2:payload} +}); +``` + +**Reducer** `rrr + ` +```javascript +import { + ${2:Action} +} from '${3:path}'; + +const defaultState = { + ${4:prop}, +}; + +const ${1:Reducer} = (state = defaultState, action = {}) => { + switch (action.type) { + case ${5:type}: + return { + ...state, + }; + + default: + return state; + } +}; + +export default ${1:Reducer}; +``` + +### Test ### + **React Test Case (chai assert and enzyme)** `rt + ` ```javascript import React from 'react'; @@ -262,7 +344,7 @@ At the time of writing, this package is not in wbond's [Package Control](https:/ #### Mac OS #### "~/Library/Application Support/Sublime Text 3/Packages" -#### Windows 7 #### +#### Windows #### "C:\Users\YOUR_USERNAME\AppData\Roaming\Sublime Text 3\Packages" ```