Contains basic snippets for React component and React-Redux components using AirBnB Style guide, AirBnB ESLint configs
Would you like me to add a snippet or contribute? Head over to the repo
Snippet | Prefix |
---|---|
React | |
Statefull Component | sfc |
Stateless Component | slc |
Redux Component | reduxComponent |
componentWillMount | cwm |
componentDidMount | cdm |
componentWillReceiveProps | cwrp |
shouldComponentUpdate | scu |
componentWillUpdate | cwu |
componentDidUpdate | cdu |
componentWillUnmount | cwum |
constructor | constructor |
binding Method | bindMethod |
state | state |
setState | setState |
props | props |
propTypes | pt |
Redux | |
mapStateToProps | mstp |
mapDispatchToProps | mdtp |
connect | connect |
reducer | reducer |
action | action |
actionType | actionType |
Other | |
[Import Library] (#importLib) | importLib |
In my team, we don't use semicolon in our code. If you want to have semicolon in your code, just add semicolon after prefix. Example:
mstp;
It'll be:
const mapStateToProps = state => {
const { key } = state;
return { key };
}
import React, { Component, PropTypes } from 'react'
import style from './style.css'
const propTypes = {
propTypes
}
const defaultProps = {
defaultProps
}
class Class extends Component {
constructor(props) {
super(props)
this.state = {
}
}
render() {
return (
<div>
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit</h1>
</div>
)
}
}
Class.propTypes = propTypes
Class.defaultProps = defaultProps
export default Class
import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import style from './style.css'
const propTypes = {
}
const defaultProps = {
}
class Class extends Component {
constructor(props) {
super(props)
this.state = {
}
}
render() {
return (
<div>
<h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit</h1>
</div>
)
}
}
Class.propTypes = propTypes
Class.defaultProps = defaultProps
const mapStateToProps = state => {
const { state } = state
return { state }
}
const mapDispatchToProps = dispatch => ({ actions }, dispatch)
export default connect(mapStateToProps, mapDispatchToProps)(Class)
import React, { PropTypes } from 'react'
import style from './style.css'
const propTypes = {
propTypes
}
const defaultProps = {
defaultProps
}
const Class = props => (
<div>
</div>
)
Class.propTypes = propTypes
Class.defaultProps = defaultProps
export default Class
componentWillMount() {
}
componentDidMount() {
}
componentWillReceiveProps(nextProps) {
}
shouldComponentUpdate(nextProps, nextState) {
}
componentWillUpdate(nextProps, nextState) {
}
componentDidUpdate(prevProps, prevState) {
}
componentWillUnmount() {
}
this.method = this.method.bind(this)
const { key } = this.state
this.setState((prevState, props) => {
key: value,
})
const { key } = this.props
props: PropTypes.types,
const mapStateToProps = state => {
const { key } = state
return { key }
}
const mapDispatchToProps = dispatch => ({
key: (params) => dispatch(func(params),
})
export default connect(mapStateToProps, mapDispatchToProps)(Class)
export const func = (params) =>
(dispatch, getState) => {
content
}
const initState = {
key: value,
}
const reducer = (state = initState, action) => {
switch (action.type) {
default:
return state
}
}
export default reducer
case TYPE:
return Object.assign({}, state, {
key: action.payload,
})
Write Library name first for suggestion