React/Redux/Jest code snippets for JavaScript and TypeScript in VS Code.
| Option | Description |
|---|---|
importReactOnTop |
Controls if snippets add import React from 'react'; at the top of components. Set to false if you have React 17+ and use the JSX transform. |
semicolon |
Controls if snippets add a semicolon at the end of the line. |
typing |
Controls if React components include TypeScript Props typing. |
- JavaScript (.js)
- JavaScript React (.jsx)
- TypeScript (.ts)
- TypeScript React (.tsx)
In the code examples below,
|marks where the cursor lands after expansion.
| Trigger | Content |
|---|---|
imp |
import name from 'module'; |
imd |
import { } from 'module'; |
ipt |
import PropTypes from 'prop-types'; |
imr |
import React from 'react'; (useful in tests) |
| Trigger | Content |
|---|---|
clg |
console.log() |
| Trigger | Content |
|---|---|
rcc |
Class component skeleton |
rccp |
Class component skeleton with prop types after the class |
rfc |
Function component skeleton |
rfcp |
Function component with prop types skeleton |
est |
Empty state object |
cdm |
componentDidMount method |
scu |
shouldComponentUpdate method |
cdu |
componentDidUpdate method |
cwu |
componentWillUnmount method |
gsb |
getSnapshotBeforeUpdate method |
gds |
static getDerivedStateFromProps method |
cdc |
componentDidCatch method |
sst |
this.setState with object as parameter |
ssf |
this.setState with function as parameter |
props |
this.props |
state |
this.state |
bnd |
Binds this to a method inside the constructor |
useState |
useState block |
useEffect |
useEffect block |
useContext |
useContext block |
| Trigger | Content |
|---|---|
rncc |
React Native class component skeleton |
rnfc |
React Native function component skeleton |
| Trigger | Content |
|---|---|
describe |
describe block |
test |
test block |
it |
it block |
| Trigger | Content |
|---|---|
pta |
PropTypes.array |
ptar |
PropTypes.array.isRequired |
pto |
PropTypes.object |
ptor |
PropTypes.object.isRequired |
ptb |
PropTypes.bool |
ptbr |
PropTypes.bool.isRequired |
ptf |
PropTypes.func |
ptfr |
PropTypes.func.isRequired |
ptn |
PropTypes.number |
ptnr |
PropTypes.number.isRequired |
pts |
PropTypes.string |
ptsr |
PropTypes.string.isRequired |
ptnd |
PropTypes.node |
ptndr |
PropTypes.node.isRequired |
ptel |
PropTypes.element |
ptelr |
PropTypes.element.isRequired |
pti |
PropTypes.instanceOf(ClassName) |
ptir |
PropTypes.instanceOf(ClassName).isRequired |
pte |
PropTypes.oneOf([...]) |
pter |
PropTypes.oneOf([...]).isRequired |
ptet |
PropTypes.oneOfType([...]) |
ptetr |
PropTypes.oneOfType([...]).isRequired |
ptao |
PropTypes.arrayOf(PropTypes.number) |
ptaor |
PropTypes.arrayOf(PropTypes.number).isRequired |
ptoo |
PropTypes.objectOf(PropTypes.number) |
ptoor |
PropTypes.objectOf(PropTypes.number).isRequired |
ptsh |
PropTypes.shape({...}) |
ptshr |
PropTypes.shape({...}).isRequired |
Full Expansions
import name from 'module';import { | } from 'module';import React from 'react';import PropTypes from 'prop-types';console.log(|);import React, { Component } from 'react';
class App extends Component {
render() {
return (
<div>
|
</div>
);
}
}
export default App;import React, { Component } from 'react';
import PropTypes from 'prop-types';
class App extends Component {
render() {
return (
<div>
|
</div>
);
}
}
App.propTypes = {
};
export default App;import React from 'react';
const App = () => {
return (
<div>
|
</div>
);
}
export default App;import React from 'react';
import PropTypes from 'prop-types';
const App = () => {
return (
<div>
|
</div>
);
};
App.propTypes = {
};
export default App;this.state = {
|
};componentDidMount() {
|
}shouldComponentUpdate(nextProps, nextState) {
|
}componentDidUpdate(prevProps, prevState) {
|
}componentWillUnmount() {
|
}getSnapshotBeforeUpdate(prevProps, prevState) {
|
}static getDerivedStateFromProps(nextProps, prevState) {
|
}componentDidCatch(error, info) {
|
}this.setState(|)this.setState((state, props) => { return { | }});this.props.|this.state.|this.| = this.|.bind(this);const [state, setState] = useState(|);useEffect(() => {
|
return () => {
};
}, []);const context = useContext(|);import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
class App extends Component {
render() {
return (
<View>
|
</View>
);
}
}
const styles = StyleSheet.create({})
export default App;import React from 'react';
import { StyleSheet, View } from 'react-native';
const App = () => {
return (
<View>
|
</View>
);
}
const styles = StyleSheet.create({})
export default App;describe('|', () => {
});test('|', () => {
});it('|', () => {
});