JS - Snippet Good!
Newest Release: v1.7.0 - Typescript Support!
Features
A collection of customized snippets intended for personal use. I've gathered and modified some of them from existing packages and created the rest.
Example (rfpe
and ptsr
snippets)
Supported VS Code Language Extensions
- javascript (.js)
- javascriptreact (.jsx)
- typescript (.ts)
- typescriptreact (.tsx)
- css (styled component shortcuts)
Debugging developer note:
If you are working on this extension, you can use the F5
key to enter debugging mode and use the snippets you are adding/modifying in any project you like.
Snippets
cl
– c
onsole l
og
console.log()
clc
– c
onsole l
og with c
olor
note: cursor starts at your message, first tab goes to color, third tab goes to the position after the css string, so you can add additional variables to log.
console.log('%cYourTextHere', 'color: cornflowerblue;')
clg
– c
onsole l
og g
roup
note: the string passed to .group
and .groupEnd
should be the same
console.group("Group Name");
console.log("I am in the group!");
console.groupEnd("Group Name");
imp
– imp
ort module
import module from 'module'
imd
– im
port module d
estructured
import { moduleName } from 'module'
imr
– im
port r
eact
import React from 'react'
imrc
– im
port r
eact and C
omponent
import React, { Component } from 'react'
imrpc
– im
port r
eact and P
ureC
omponent
import React, { PureComponent } from 'react'
imrus
– im
port r
eact and u
seS
tate
import React, { useState } from 'react'
imrue
– im
port r
eact and u
seE
ffect
import React, { useEffect } from 'react'
imruse
or imrues
– im
port r
eact, u
seS
tate and useE
ffect
import React, { useState, useEffect } from 'react'
impt
– im
port P
ropT
ypes
import PropTypes from 'prop-types'
imes
– im
port e
nzyme's s
hallow module
import { shallow } from 'enzyme'
imem
– im
port e
nzyme's m
ount module
import { mount } from 'enzyme'
imesm
– im
port e
nzyme's s
hallow and m
ount modules
import { shallow, mount } from 'enzyme'
exp
– exp
ort default module
export default module
rce
– R
eact C
omponent class with e
xport after
import React, { Component } from "react";
class Module extends Component {
render() {
return <div></div>;
}
}
export default Module;
rfe
or rse
(deprecated) – R
eact f
unctional component with e
xport after
import React from "react";
const Module = () => {
return <div></div>;
};
export default Module;
rus
– R
eact u
seS
tate statement
Note: this snippet takes the state
placeholder and captializes the setState
counterpart using snippet transforms. Just type whatever your state
variable is and press "Tab" to activate the transform and move on to the next placeholder.
Note of Note: I can't get this to work with the "Vim" extension, not matter how hard I try. Sorry :(
const [state, setState] = useState();
rue
– R
eact u
seE
ffect statement
Note: I didn't place the 2nd argument of useEffect
in this snippet, because I often do not know if I'm going to need it, or what props/state will go in there until I'm done writing it. It also becomes troublesome to delete the placeholder if you don't want it
useEffect(() => {});
rfeus
or rfes
– R
eact f
unctional component with e
xport after and u
seS
tate setup
Note: this snippet takes the state
placeholder and captializes the setState
counterpart using snippet transforms. Just type whatever your state
variable is and press "Tab" to activate the transform and move on to the next placeholder.
Note of Note: I can't get this to work with the "Vim" extension, not matter how hard I try. Sorry :(
import React, { useState } from "react";
const Module = () => {
const [state, setState] = useState();
return <div></div>;
};
export default Module;
rfc
– R
eact f
unctional c
omponent
const Module = () => {
return <div></div>;
};
rfpe
– R
eact f
unctional component with P
ropTypes and e
xport after
import React from "react";
import PropTypes from "prop-types";
const Module = () => {
return <div></div>;
};
Module.propTypes = {};
export default Module;
pt
– P
ropT
ypes object
Useful if you have already created a component and decide you need Proptypes after. Uses the filename as the default for Module
.
Note:: VSCode snippets do not autocomplete during placeholders, so you'll want to hit escape after tabbing inside of the object
Module.propTypes = {};
cdu
– React: c
omponentD
idU
pdate
componentDidUpdate(prevProps, prevState) {
}
cdm
– React: c
omponentD
idM
ount
componentDidMount() {
}
cdml
– React: c
omponentD
idM
ount with l
og
componentDidMount() {
console.log('Module Mounted')
}
cdmlc
– React: c
omponentD
idM
ount with l
og (c
olor)
componentDidMount() {
console.log('%cModule Mounted', 'color: cornflowerblue;')
}
scp
– S
tyled C
omponents: p
rops callback
${props => props.};
sct
– S
tyled C
omponents: t
heme callback
${({ theme }) => theme.};
PropType snippets:
Prefix |
Output |
pta |
PropTypes.array |
ptar |
PropType.array.isRequired |
ptb |
PropType.bool |
ptbr |
PropType.bool.isRequired |
ptel |
PropType.element |
ptelr |
PropType.element.isRequired |
ptf |
PropType.func |
ptfr |
PropType.func.isRequired |
ptnd |
PropType.node |
ptndr |
PropType.node.isRequired |
ptn |
PropType.number |
ptnr |
PropType.number.isRequired |
pto |
PropType.object |
ptor |
PropType.object.isRequired |
pts |
PropType.string |
ptsr |
PropType.string.isRequired |
ptsh |
PropType.shape({}) |
ptshr |
PropType.shape({}).isRequired |
des
– Testing des
cribe block
describe("", () => {});
tit
– T
esting it
block
it("", () => {});
expss
– Testing exp
ect to match s
naps
hot
expect().toMatchSnapshot()
expte
or exp==
– Testing exp
ect t
o e
qual
expect().toEqual()
exptb
– Testing exp
ect t
o b
e
expect().toBe()
exptbn
– Testing exp
ect to
be
n`ull
expect().toBeNull()
shal
– Enzyme shal
low mount component
const component = shallow(<Component />
shalp
– Enzyme shal
low mount component with premade p
rops object
const component = shallow(<Component {...props} />
mnt
– Enzyme full m
ount
component
const component = mount(<Component />
mntp
– Enzyme full m
ount
component with premade p
rops object
const component = mount(<Component {...props} />
rtlbs
– R
eact T
esting L
ibrary: B
oots
trap
import React from "react";
import { render } from "@testing-library/react";
import TestComponent from ".";
describe("TestComponent", () => {
test("should render", () => {
const { container } = render(<TestComponent></TestComponent>);
expect(container).toMatchSnapshot();
});
});
rtlss
– R
eact T
esting L
ibrary: S
naps
hot
expect(container).toMatchSnapshot()
tst
– Testing: t
est
block
test("", () => {});
sbc
– S
toryb
ook C
omponent
Quick story setup for a component in the same directory as the story.
import React from "react";
import { storiesOf } from "@storybook/react";
import Component from ".";
storiesOf("Components|Component", module).add("default", () => (
<Component></Component>
));
Typescript Snippets
sbc
– s
toryb
ook c
omponent
Quick story setup for a component in the same directory as the story.
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { Example } from './'
export default {
title: 'Components/Example',
component: Example,
} as ComponentMeta<typeof Example>
const Template: ComponentStory<typeof Example> = (args) => <Example {...args} />
export const Default = Template.bind({})
Default.args = {
children: 'I am the Example Component',
}
Release Notes
See Changelog