ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

React Development Snippets

by jeantimex ST2/ST3

Save time in writing React codes

Details

Installs

  • Total 17K
  • Win 8K
  • OS X 7K
  • Linux 3K
May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6
Windows 13 12 11 14 12 16 17 18 5 10 18 19 14 20 10 10 6 14 15 14 11 11 8 16 13 12 18 21 22 8 10 20 19 14 19 16 12 8 22 20 23 25 19 10 8 14
OS X 6 7 5 5 7 6 8 18 2 6 4 4 7 13 2 3 8 13 7 8 7 5 6 4 7 7 12 16 6 6 2 5 11 8 14 13 8 8 11 8 5 10 11 2 3 2
Linux 4 2 2 5 9 7 8 1 3 2 6 5 3 8 5 0 4 11 7 8 4 2 1 6 8 2 5 4 5 1 3 4 8 4 7 5 2 4 3 9 6 5 3 1 4 4

Readme

Source
raw.​githubusercontent.​com

React Development Snippets

Feeling bored with typing or even copying React codes to write React components and test cases? If you use Sublime, hope these code snippets can help you enjoy writing your 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).

Installation

Use Package Control

  • Make sure you have Package Manager installed
  • Launch the command palette: ⌘+shift+p on MacOS, ctrl+shift+p on Windows
  • Type install, select Package Control: Install Package
  • Type React, select React Development Snippets

Without Package Control

Navigate to your Sublime Text packages folder and git clone our project.

MacOS

“/Users/{user}/Library/Application Support/Sublime Text {2|3}/Packages”

Windows

“C:\Users{user}\AppData\Roaming\Sublime Text {2|3}\Packages”

git clone https://github.com/jeantimex/react-sublime-snippet.git "React-Development-Snippets"

Snippets

React

ES6 Class Component rcc + <TAB>
rcc
“javascript import React, { Component, PropTypes } from 'react';

class ${1:Component} extends Component { static propTypes = { className: PropTypes.string, };

constructor(props) {
    super(props);
}

render() {
    return (
        ${0}
    );
}

}

export default ${1:Component};

**ES6 Class Component with injectIntl** `rcci + <TAB>`
```javascript
import React, { Component, PropTypes } from 'react';
import { injectIntl, intlShape } from 'react-intl';

class ${1:Component} extends Component {
    static propTypes = {
        intl: intlShape.isRequired,
    };

    constructor(props) {
        super(props);
    }

    render() {
        const { formatMessage } = this.props.intl;

        return (
            ${0}
        );
    }
}

export default injectIntl(${1:Component});

Functional Component rfc + <TAB>
rfc
”javascript import React, { PropTypes } from 'react';

const ${1:Component} = ({ className = '', }) => { return (

${0}
); };

${1:Component}.displayName = '${1:Component}';

${1:Component}.propTypes = { className: PropTypes.string, };

export default ${1:Component};

**Functional Component with injectIntl** `rfci + <TAB>`
```javascript
import React, { PropTypes } from 'react';
import { injectIntl, intlShape } from 'react-intl';

const ${1:Component} = ({
    intl,
}) => {
    const { formatMessage } = intl;

    return (
        ${0}
    );
};

${1:Component}.displayName = '${1:Component}';

${1:Component}.propTypes = {
    intl: intlShape.isRequired,
};

export { ${1:Component} };

export default injectIntl(${1:Component});

static propTypes rspt + <TAB> “javascript static propTypes = { ${1:prop}: PropTypes.${2:string}, };

**static defaultProps** `rdp + <TAB>`
```javascript
static defaultProps = {
    ${1:prop}: ${2:value},
};

Define Formatted Messages rdm + <TAB> ”javascript const messages = defineMessages({ ${1:message}: { defaultMessage: '${2:default message}', description: '${3:description}', id: '${4:id}', }, });

**Define New Formatted Message** `rnm + <TAB>`
```javascript
${1:message}: {
    defaultMessage: '${2:default message}',
    description: '${3:description}',
    id: '${4:id}',
},

componentDidMount() rcdm + <TAB> “javascript componentDidMount() { ${1} }

**componentDidUpdate(prevProps, prevState)** `rdu + <TAB>`
```javascript
componentDidUpdate(prevProps, prevState) {
    ${1}
}

componentWillMount rcwm + <TAB> ”javascript componentWillMount() { ${1} }

**componentWillReceiveProps(nextProps)** `rcwrp + <TAB>`
```javascript
componentWillReceiveProps(nextProps) {
    ${1}
}

componentWillUnmount() rcwum + <TAB> “javascript componentWillUnmount() { ${1} }

**componentWillUpdate(nextProps, nextState)** `rcwu + <TAB>`
```javascript
componentWillUpdate(nextProps, nextState) {
    ${1}
}

shouldComponentUpdate(nextProps, nextState) rscu + <TAB> ”javascript shouldComponentUpdate(nextProps, nextState) { return ${1}; }

### Redux ###
**Redux Component** `rrc + <TAB>`<br />
![rrc](screenshots/rrc.gif)<br />
```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 + <TAB> “javascript export const ${1:action} = (${2:payload}) => ({ type: ${3:type}, ${2:payload} });

**Reducer** `rrr + <TAB>`
```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 + <TAB>
rt
”javascript import React from 'react'; import { assert } from 'chai'; import { shallow } from 'enzyme'; import ${1:Component} from '${2:../component}';

const sandbox = sinon.sandbox.create();

describe('${1:Component}', () => { afterEach(() => { sandbox.verifyAndRestore(); });

beforeEach(() => {
    ${3}
});

it('should render ${1:Component} correctly', () => {
    const component = shallow(
        <${1:Component} />
    );
    ${4}
});

});

**React Test Describe** `rtd + <TAB>`
```javascript
describe('${1:...}', () => {
    afterEach(() => {
        ${2}
    });

    beforeEach(() => {
        ${3}
    });

    it('should ${4:...}', () => {
        ${0}
    });
});

React Test it() rti + <TAB> “javascript it('should ${1:…}', () => { ${0} });

**import** `rim + <TAB>`
```javascript
import ${1:Package} from '${2:path}';

Authors

License

This project is licensed under the MIT License.