• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Save time in writing React codes

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

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>

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

import React, { PropTypes } from 'react';

const ${1:Component} = ({
    className = '',
}) => {
    return (
        <div>
            ${0}
        </div>
    );
};

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

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

export default ${1:Component};

Functional Component with injectIntl rfci + <TAB>

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>

static propTypes = {
    ${1:prop}: PropTypes.${2:string},
};

static defaultProps rdp + <TAB>

static defaultProps = {
    ${1:prop}: ${2:value},
};

Define Formatted Messages rdm + <TAB>

const messages = defineMessages({
    ${1:message}: {
        defaultMessage: '${2:default message}',
        description: '${3:description}',
        id: '${4:id}',
    },
});

Define New Formatted Message rnm + <TAB>

${1:message}: {
    defaultMessage: '${2:default message}',
    description: '${3:description}',
    id: '${4:id}',
},

componentDidMount() rcdm + <TAB>

componentDidMount() {
    ${1}
}

componentDidUpdate(prevProps, prevState) rdu + <TAB>

componentDidUpdate(prevProps, prevState) {
    ${1}
}

componentWillMount rcwm + <TAB>

componentWillMount() {
    ${1}
}

componentWillReceiveProps(nextProps) rcwrp + <TAB>

componentWillReceiveProps(nextProps) {
    ${1}
}

componentWillUnmount() rcwum + <TAB>

componentWillUnmount() {
    ${1}
}

componentWillUpdate(nextProps, nextState) rcwu + <TAB>

componentWillUpdate(nextProps, nextState) {
    ${1}
}

shouldComponentUpdate(nextProps, nextState) rscu + <TAB>

shouldComponentUpdate(nextProps, nextState) {
    return ${1};
}

Redux

Redux Component rrc + <TAB>
rrc

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>

export const ${1:action} = (${2:payload}) => ({
    type: ${3:type},
    ${2:payload}
});

Reducer rrr + <TAB>

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

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>

describe('${1:...}', () => {
    afterEach(() => {
        ${2}
    });

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

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

React Test it() rti + <TAB>

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

import rim + <TAB>

import ${1:Package} from '${2:path}';

Authors

License

This project is licensed under the MIT License.

More Repositories

1

ios-swift-collapsible-table-section

📱 A simple iOS Swift project demonstrates how to implement collapsible table section.
Swift
1,209
star
2

javascript-problems-and-solutions

🔱 A collection of JavaScript problems and solutions for studying algorithms.
JavaScript
484
star
3

CollapsibleTableSectionViewController

🎉 Swift library to support collapsible sections in a table view.
Swift
350
star
4

ios-swift-collapsible-table-section-in-grouped-section

A simple demo that demonstrates how to implement collapsible table sections in grouped table view.
Swift
86
star
5

klotski

🔸 The JavaScript algorithm for solving klotski game.
JavaScript
38
star
6

five-in-a-row

A classic Chinese board game built with React and Socket.io.
JavaScript
36
star
7

react-webpack-boilerplate

React Webpack Boilerplate
JavaScript
22
star
8

apple-watch-ui

Implement Apple Watch UI with AngularJS
JavaScript
18
star
9

hua-rong-dao-html

AngularJS HTML5 puzzle game 华容道
JavaScript
17
star
10

SwiftyLib

A CocoaPods library written in Swift
Ruby
12
star
11

ios-swift-highlight-searchbar-placeholder

A demo shows how to highlight certain text in the search bar.
Swift
10
star
12

swift-material-uitextfield

Another material-style UITextField written in Swift.
Swift
8
star
13

generator-react-webpack-scaffold

A Yeoman generator that scaffolds React application with Webpack.
JavaScript
8
star
14

react-webapp-boilerplate

🚀 React Webapp Boilerplate demonstrates how to scaffold a web application using React, Webpack and Jest.
JavaScript
8
star
15

how-to-implement-promise

How to implement a Promise that is Promises/A+ compliant using vanilla JavaScript.
JavaScript
5
star
16

slush-html5-app

Scaffold your next HTML5 app with webpack and webpack dev server.
JavaScript
2
star
17

react-electron-boilerplate

🚀 React Electron Boilerplate demonstrates how to scaffold a desktop application using React and Electron.
JavaScript
2
star
18

closure-playground

A playground for learning closure
1
star
19

threejs-globe

Created with CodeSandbox
JavaScript
1
star
20

SwiftyCalculator

A Cocoapods calculator library written in Swift
Swift
1
star
21

react-advanced-markers

For debugging an issue with Advanced Markers and React
JavaScript
1
star
22

generator-typescript-webapp

This Yeoman generator helps you scaffold your next web application with TypeScript and Webpack.
JavaScript
1
star
23

traffic-old

A road traffic simulation based on the intelligent driver model (IDW)
JavaScript
1
star
24

react-webpack-code-splitting

🔱 A demo of how to split the code for a React Webpack application.
JavaScript
1
star
25

calculator

A UMD calculator
JavaScript
1
star
26

chat-app

A simple chat app built with Objective-C and MultipeerConnectivity
Objective-C
1
star
27

generator-html-app

Scaffold your next HTML5 app with webpack and webpack dev server.
JavaScript
1
star
28

generator-web-application

Scaffold your next web application for prototyping and production.
JavaScript
1
star
29

iBlog

iOS blog app
Objective-C
1
star
30

webgl2-study

Stores all the codes that I learn about WebGL2
TypeScript
1
star
31

dotfiles

My iTerm2, tmux and neovim setup
Lua
1
star
32

tensorflow-study

My TensorFlow projects
TypeScript
1
star
33

umd-lib

Another JavaScript UMD library
JavaScript
1
star
34

flex-badge-button

Extends Flex button component to have iOS-like badge icon.
1
star
35

laioffer-demos

Demo projects for Laioffer Nodejs class.
JavaScript
1
star
36

slush-webpack-html

🚀 Scaffold your next html5 app with webpack and webpack dev server.
JavaScript
1
star
37

material-color-palettes

Material color palettes
JavaScript
1
star
38

genetic-flappy-bird

JavaScript
1
star
39

swift-scroll-pages-with-transition

A demo shows how to implement transition when scrolling the pages.
Swift
1
star
40

slush-react-app

Scaffold your next React app with webpack and webpack dev server.
JavaScript
1
star
41

generator-vanilla-webapp

This Yeoman generator helps you scaffold your next web application with Vanilla JavaScript and Webpack.
JavaScript
1
star
42

genetic-algorithm

Implement Genetic Algorithm in JavaScript
JavaScript
1
star
43

neural-flappy-bird

A tensorflow reinforcement trained flappy bird
TypeScript
1
star
44

vanilla-javascript-drag-n-drop

Created with CodeSandbox
JavaScript
1
star
45

tensorflow-playground

Tensorflow Playground
JavaScript
1
star
46

generator-vanilla-react-webapp

Vanilla React Web Application Yeoman Generator
JavaScript
1
star
47

nyc-demo

A demo of using nyc
JavaScript
1
star
48

color-magnifier

A Chrome extension for picking color on web page
JavaScript
1
star