-
Notifications
You must be signed in to change notification settings - Fork 474
Javascript, Typescript, Javascriptreact, Typescriptreact
NOTE: this list doesn't show all snippets included with this repository, meaning that there's more than what you see here.
- declarations
- flow control
- functions
- iterables
- objects and classes
- returning values
- types
- promises
- ES6 modules
- testing
- console
- timers
- DOM
- Node.js
- miscellaneous
var ${1:name}
var ${1:name} = ${2:value}
let ${1:name}
let ${1:name} = await ${2:value}
let ${1:name} = yield ${2:value}
const ${1:name}
const { ${1:name} } = ${2:value}
const ${1:name} = await ${2:value}
const { ${1:name} } = await ${2:value}
const ${1:name} = (${2:arguments}) => {\n\treturn ${0}\n}
const ${1:name} = yield ${2:value}
if (${1:condition}) {
${0}
}
${1:cond} ? ${2:true} : ${3: false}
const ${0} = ${1:cond} ? ${2:true} : ${3: false}
else {
${0}
}
if (${1:condition}) {
${0}
} else {
}
else if (${1:condition}) {
${0}
}
for (let ${1:i} = 0, ${2:len} = ${3:iterable}.length ${1:i} < ${2:len}; ${1:i}++) {
${0}
}
for (let ${1:key} in ${2:source}) {
if (${2:source}.hasOwnProperty(${1:key})) {
${0}
}
}
for (const ${1:key} of ${2:source}) {
${0}
}
while (${1:condition}) {
${0}
}
let ${1:array}Index = ${1:array}.length
while (${1:array}Index--) {
${0}
}
try {
${0}
} catch (${1:err}) {
}
try {
${0}
} finally {
}
try {
${0}
} catch (${1:err}) {
} finally {
}
function (${1:arguments}) {${0}}
function ${1:name}(${2:arguments}) {
${0}
}
async function (${1:arguments}) {
${0}
}
async (${1:arguments}) => {
${0}
}
;(function (${1:arguments}) {
${0}
})(${2})
;(async (${1:arguments}) => {
${0}
})(${2})
${1:fn}.apply(${2:this}, ${3:arguments})
${1:fn}.call(${2:this}, ${3:arguments})
${1:fn}.bind(${2:this}, ${3:arguments})
(${1:arguments}) => ${2:statement}
({${1:arguments}}) => ${2:statement}
({${1:arguments}}) => ${1:arguments}
(${1:arguments}) => {
${0}
}
(${1:arguments}) => {
return ${0}
}
function* (${1:arguments}) {
${0}
}
function* ${1:name}(${1:arguments}) {
${0}
}
${1:iterable}.forEach((${2:item}) => {
${0}
})
${1:iterable}.map((${2:item}) => {
${0}
})
${1:iterable}.reduce((${2:previous}, ${3:current}) => {
${0}
}${4:, initial})
${1:iterable}.filter((${2:item}) => {
${0}
})
${1:iterable}.find((${2:item}) => {
${0}
})
${1:iterable}.every((${2:item}) => {
${0}
})
${1:iterable}.some((${2:item}) => {
${0}
})
class ${1:name} {
constructor(${2:arguments}) {
${0}
}
}
class ${1:name} extends ${2:base} {
constructor(${2:arguments}) {
super(${2:arguments})
${0}
}
}
${1:method} (${2:arguments}) {
${0}
}
get ${1:property} () {
${0}
}
set ${1:property} (${2:value}) {
${0}
}
get ${1:property} () {
${0}
}
set ${1:property} (${2:value}) {
}
${1:Class}.prototype.${2:methodName} = function (${3:arguments}) {
${0}
}
Object.keys(${1:obj})
Object.values(${1:obj})
Object.entries(${1:obj})
Object.create(${1:obj})
Object.assign(${1:dest}, ${2:source})
Object.getOwnPropertyDescriptor(${1:dest}, '${2:prop}')
Object.defineProperty(${1:dest}, '${2:prop}', {
${0}
})
return ${0}
return this
return null
return (${1:arguments}) => ${2:statement}
return {
${0}
}
return [
${0}
]
return new Promise((resolve, reject) => {
${0}
})
typeof ${1:source} === '${2:undefined}'
this.
${1:source} instanceof ${2:Object}
Array.isArray(${1:source})
Promise.all(${1:value})
new Promise((resolve, reject) => {
${0}
})
${1:promise}.then((${2:value}) => {
${0}
})
${1:promise}.catch(error => {
${0}
})
export ${1:member}
export default ${1:member}
export default function ${1:name} (${2:arguments}) {\n\t${0}\n}
export const ${1:member} = ${2:value}
export function ${1:member} (${2:arguments}) {\n\t${0}\n}
import ${1:*} from '${2:module}'
import ${1:*} as ${2:name} from '${3:module}'
import { $1 } from '${2:module}'
describe('${1:description}', function () {
${0}
})
describe('${TM_FILENAME_BASE}', function () {
${0}
})
it('${1:description}', async () => {
${0}
})
it('${1:description}', (done) => {
${0}
})
it('${1:description}', () => {
${0}
})
before(function () {
${0}
})
beforeEach(function () {
${0}
})
after(function () {
${0}
})
afterEach(function () {
${0}
})
setTimeout(() => {
${0}
}, ${1:delay})
setTimeout(() => {
${0}
}, ${1:delay})
setImmediate(() => {
${0}
})
${1:document}.addEventListener('${2:event}', ${3:ev} => {
${0}
})
${1:document}.removeEventListener('${2:event}', ${3:listener})
ev.preventDefault()
ev.stopPropagation()
return false
${1:document}.getElementById('${2:id}')
Array.from(${1:document}.getElementsByClassName('${2:class}'))
Array.from(${1:document}.getElementsByTagName('${2:tag}'))
${1:document}.querySelector('${2:selector}')
Array.from(${1:document}.querySelectorAll('${2:selector}'))
${1:document}.createDocumentFragment(${2:elem});
${1:document}.createElement(${2:elem});
${1:document}.appendChild(${2:elem});
${1:document}.removeChild(${2:elem});
${1:document}.classList.add('${2:class}');
${1:document}.classList.toggle('${2:class}');
${1:document}.classList.remove('${2:class}');
${1:document}.getAttribute('${2:attr}');
${1:document}.setAttribute('${2:attr}', ${3:value});
${1:document}.removeAttribute('${2:attr}');
function (err, ${1:value}) {
if (err) throw err
t${0}
}
require('${1:module}')
const ${1:module} = require('${1:module}')
exports.${1:name} = ${2:value}
module.exports = ${1:name}
${1:emitter}.on('${2:event}', (${3:arguments}) => {
${0}
})
'use strict'
JSON.stringify($0)
JSON.parse($0)
await ${0}
await Promise.all(${1:value})
await Promise.all(${1:array}.map((async ${2:value}) => {\n\t${0}\n}))
await new Promise((r) => setTimeout(r, ${0}))
console.log(${0})
console.log('${0}:', ${0})
console.error(${0})
console.warn(${0})
console.dir(${0})
Are only enabled in jsx
or tsx
files. If you write your jsx in js
files, you need to copy the react.json
files manually and add it to your custom snippets.
If you're not writing react, including them should not really bother you because they are not short as the regular JS snippets. Also IMHO react is the leading solution for FE apps deserves to be included by default, because any JS dev will have to write some react eventually over the course of his/her careeer. By having them in a single package we can easily make sure --there aren't any conflicts in the trigger prefixes.
- JavaScript (.js)
- TypeScript (.ts)
- JavaScript React (.jsx)
- TypeScript React (.tsx)
These were originally taken from https://github.com/TimonVS/vscode-react-standard because the maintainer wasn't able to publish a new version for months even when there was a considerable flaw in the released version. Below is a list of all available snippets and the triggers of each one.
Trigger | Content |
---|---|
j |
jsx element |
dp |
destructuring of props |
ds |
destructuring of props |
jc |
jsx self-closed element |
jm |
jsx elements map |
jmr |
jsx elements map with return |
rfc |
functional component. Prefer for 99% of new react component |
rfce |
functional component with emotion css import |
rcc |
class component skeleton |
rccp |
class component skeleton with prop types after the class |
rcjc |
class component skeleton without import and default export lines |
rcfc |
class component skeleton that contains all the lifecycle methods |
rfcp |
stateless component with prop types skeleton |
rpt |
empty propTypes declaration |
con |
class default constructor with props |
conc |
class default constructor with props and context |
est |
empty state object |
cwm |
componentWillMount method |
cdm |
componentDidMount method |
cwr |
componentWillReceiveProps method |
cgd |
componentGetDerivedStateFromProps method |
scu |
shouldComponentUpdate method |
cwup |
componentWillUpdate method |
cdup |
componentDidUpdate method |
cwun |
componentWillUnmount method |
ren |
render method |
sst |
this.setState with object as parameter |
ssf |
this.setState with function as parameter |
tp |
this.props |
ts |
this.state |
us |
useState |
ue |
useEffect |
uec |
useEffect with a cleanup function |
ur |
useRef |
cc |
createContext |
uc |
useContext |
ume |
useMemo |
------- | ---------------------------------------------------------------- |
uq |
useQuery to be used with graphql-codegen |
uqc |
useQuery that loads up data for current component, to be used with graphql-codegen |
um |
useMutation to be used with graphql-codegen |
uqg |
useQuery with raw gql |
umg |
useMutation with raw gql |
There are also snippets to be triggered with a text selection(trigger via insert snippet command):
jsx element wrap selection
The following table lists all the snippets that can be used for prop types.
Every snippet regarding prop types begins with pt
so it's easy to group it all together and explore all the available options.
On top of that each prop type snippets has one equivalent when we need to declare that this property is also required.
For example pta
creates the PropTypes.array
and ptar
creates the PropTypes.array.isRequired
Trigger | Content |
---|---|
pta |
PropTypes.array, |
ptar |
PropTypes.array.isRequired, |
ptb |
PropTypes.bool, |
ptbr |
PropTypes.bool.isRequired, |
ptf |
PropTypes.func, |
ptfr |
PropTypes.func.isRequired, |
ptn |
PropTypes.number, |
ptnr |
PropTypes.number.isRequired, |
pto |
PropTypes.object., |
ptor |
PropTypes.object.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(['News', 'Photos']), |
pter |
PropTypes.oneOf(['News', 'Photos']).isRequired, |
ptet |
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), |
ptetr |
PropTypes.oneOfType([PropTypes.string, PropTypes.number]).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({color: PropTypes.string, fontSize: PropTypes.number}), |
ptshr |
PropTypes.shape({color: PropTypes.string, fontSize: PropTypes.number}).isRequired, |