The essential collection of React Snippets.
Only what you need and nothing more. No Redux. No React Native.
Simply, simple React snippets.
These snippets were selected carefully from my own day-to-day React use. Not everything in React is included here. This is a hand selected set of snippets that work the way that you would expect, not just a copy of the documentation.
Snippet | Renders |
---|---|
imr |
Import React |
imrc |
Import React / Component |
cc |
Class Component |
ccc |
Class Component With Constructor |
sfc |
Stateless Function Component |
cdm |
componentDidMount |
cwm |
componentWillMount |
cwrp |
componentWillReceiveProps |
scu |
shouldComponentUpdate |
cwu |
componentWillUpdate |
cdu |
componentDidUpdate |
cwu |
componentWillUpdate |
ss |
setState |
ren |
render |
import React from 'react';
import React, { Component } from 'react';
class MyClass extends Component {
render() {
return <div />;
}
}
export default MyClass;
class MyClass extends Component {
constructor(props) {
super(props);
this.state = { };
}
render() {
return <div />;
}
}
export default MyClass;
const MyComponent = props => {
return <div />;
};
export default MyComponent;
componentDidMount() {
}
componentWillMount() {
}
componentWillReceiveProps(nextProps) {
}
shouldComponentUpdate(nextProps, nextState) {
}
componentWillUpdate() {
}
componentDidUpdate(prevProps) {
}
componentWillUnmount() {
}
this.setState({ : });
render() {
return (
)
}
- Change "Create Class With Constructor" to "Create Class With State"
- Pass
props
to constructor and super call - Add
this.state
to constructor - Pass
prevProps
tocomponentDidUpdate
Complete README with samples
Initial release of Simple React Snippets 🔥