A collection of customized snippets intended for personal use. I've gathered and modified some of them from existing packages and created the rest.
- javascript (.js)
- javascriptreact (.jsx)
- typescript (.ts)
- typescriptreact (.tsx)
- css (styled component shortcuts)
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.
console.log()
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;')
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");
import module from 'module'
import { moduleName } from 'module'
import React from 'react'
import React, { Component } from 'react'
import React, { PureComponent } from 'react'
import React, { useState } from 'react'
import React, { useEffect } from 'react'
import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import { shallow } from 'enzyme'
import { mount } from 'enzyme'
import { shallow, mount } from 'enzyme'
export default module
import React, { Component } from "react";
class Module extends Component {
render() {
return <div></div>;
}
}
export default Module;
import React from "react";
const Module = () => {
return <div></div>;
};
export default Module;
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();
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(() => {});
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;
const Module = () => {
return <div></div>;
};
import React from "react";
import PropTypes from "prop-types";
const Module = () => {
return <div></div>;
};
Module.propTypes = {};
export default Module;
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 = {};
componentDidUpdate(prevProps, prevState) {
}
componentDidMount() {
}
componentDidMount() {
console.log('Module Mounted')
}
componentDidMount() {
console.log('%cModule Mounted', 'color: cornflowerblue;')
}
${props => props.};
${({ theme }) => theme.};
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 |
describe("", () => {});
it("", () => {});
expect().toMatchSnapshot()
expect().toEqual()
expect().toBe()
expect().toBeNull()
const component = shallow(<Component />
const component = shallow(<Component {...props} />
const component = mount(<Component />
const component = mount(<Component {...props} />
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();
});
});
expect(container).toMatchSnapshot()
test("", () => {});
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>
));
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',
}
See Changelog