Thanks for giving this a go. Hope this helps and makes your coding more efficient and fun.
Animations coming soon.
Pull requests for animations or any other contributions are most welcome!
- Launch the Command Pallete (Ctrl + Shift + P or ⌘Cmd + Shift + P) and type "Install Extensions" (or navigate from the sidebar to Extensions tab).
- In search box type in "iJS" and choose the React Next.js Snippets by iJS
- Install the extension (you may need to relaunch VS Code)
- Get a coffee, a cookie and celebrate by writing some Next.js code more effeciently than ever!
- JavaScript (.js)
- TypeScript (.ts)
- JavaScript React (.jsx)
- TypeScript React (.tsx)
Below is a list of all available snippets and the triggers of each one. The ⇥ means the TAB
key.
Trigger | Content |
---|---|
imr→ |
Explicitly import React |
imrc→ |
Import React { Component } |
imst→ |
(16.8+) useState import |
ust→ |
Use (16.8+) useState hook |
imeff→ |
(16.8+) useEffect import |
uueff→ |
use useEffect |
imctx→ |
(16.8+) useContext import |
uctx→ |
Use React useContext hook |
immem→ |
(16.8+) useMemo import |
imref→ |
(16.8+) useRef import |
imimphan→ |
(16.8+) useImperativeHandle import |
imlayeff→ |
(16.8+) useLayoutEffect import |
imdebval→ |
(16.8+) useDebugValue import |
imt→ |
Import PropTypes |
cc |
Class Component |
ccc→ |
Class Component With Constructor |
fc→ |
Functional Component |
fce→ |
Functional Component as named export |
fcde→ |
Functional Component with default export |
fcst→ |
Functional Component with useState Hook |
Trigger | Content |
---|---|
gip→ |
getInitialProps() outside component |
ccgip→ |
static getInitialProps() inside class component |
ccgipaq→ |
static getInitialProps() withApollo() expose query |
Trigger | Content |
---|---|
gsp→ |
exports getStaticProps() |
imgsp |
import GetStaticProps type |
iminfgsp |
import InferGetStaticPropsType |
ninfgsp |
use InferGetStaticPropsType |
Trigger | Content |
---|---|
gssp→ |
exports getServerSideProps() |
imgvsp→ |
imports GetServerSideProps type |
iminfgvsp→ |
imports InferGetServerSidePropsType |
ninfgvsp→ |
use InferGetServerSidePropsType |
Trigger | Content |
---|---|
gspaths→ |
exports getStaticPaths() |
imgspaths→ |
import GetStaticPaths |
Trigger | Content |
---|---|
imhd→ |
import Head |
nhd→ |
Use Head |
Trigger | Content |
---|---|
imimg→ |
import Image |
nimg→ |
Use sized image |
nuimg→ |
Use unsized image |
Trigger | Content |
---|---|
imlnk→ |
import Link |
nlnk→ |
Use Link |
nlnkpath→ |
Next Link tag with pathname; |
nlnkdyn→ |
Next Link tag with dynamic route; |
Trigger | Content |
---|---|
imrtr→ |
import Router |
nrtr→ |
Declare Next.js Router from useRouter |
nqprtr→ |
Destructure Next.js query param from Router from useRouter |
imrtrwr→ |
import Router and withRouter HOC |
imusrtr→ |
import Router hook |
- More snippets to come, stay tuned!
import React from "react";
import { Component } from "react";
import { useState } from "react";
const [value, setValue] = useState(${1:INITIAL_VALUE});
import { useEffect } from "react";
import { useContext } from "react";
const | = useContext(|);';
import { useMemo } from "react";
import { useRef } from "react";
import { useImperativeHandle } from "react";
import { useLayoutEffect } from "react";
import { useDebugValue } from "react";
import PropTypes from "prop-types";
import PropTypes from "prop-types";
import React, { PureComponent } from "react";
class | extends Component {
state = { | }
render() {
return ( | );
}
}
export default |;
class | extends React.Component {
constructor(props) {
super(props);
this.state = { | }
}
render() {
return ( | );
}
}
export default |;
const | = (|) => {
return ( | );
}
export const | = (|) => {
return ( | );
}
const | = (|) => {
return ( | );
}
export default |;
import { useState } from 'react';
const | = props => {
const [value, setValue] = useState(${1:INITIAL_VALUE});
return ( | );
};
export default |;
import Head from "next/head";
<Head> | </Head>
import { GetStaticProps } from "next";
import { InferGetStaticPropsType } from "next";
function |({ posts }: InferGetStaticPropsType<typeof getStaticProps>) {
return |
}
|.getInitialProps = async ({ req }) => {
return |
}
static async getInitialProps() { return { | }; }
static async getInitialProps({ Component, ctx }) {
let pageProps = {};
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}
pageProps.query = ctx.query;
pageProps.asPath = ctx.asPath;
return { pageProps };
}
export async function getStaticProps(context) {
return {
props: { | }, // will be passed to the page component as props
}
}
export const getStaticProps: GetStaticProps = async (context) => {
return {
props: { | } // will be passed to the page component as props
};
}
export async function getStaticPaths() {
return {
paths: [
{ params: { | } } // See https://nextjs.org/docs/basic-features/data-fetching#the-paths-key-required
],
fallback: | // See https://nextjs.org/docs/basic-features/data-fetching#fallback-true
};
}
export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: [
{ params: { | } }
],
fallback: |
};
}
export async function getServerSideProps(context) {
return {
props: { | }, // will be passed to the page component as props
};
}
export const getServerSideProps: GetServerSideProps = async (context) => {
return {
props: { | },
};
}
import { GetServerSideProps } from "next";
import { InferGetServerSidePropsType } from "next";
function |({ data }: InferGetServerSidePropsType<typeof getServerSideProps>) {
return |
}
import Link from "next/link";
<Image alt="|" src="|" width="|" height="|" />
<Image alt="|" src="|" width="|" unsized />
<Link href="|">
<a>|</a>
</Link>
<Link href={{ pathname: |, query: { queryName: | } }}>
<a>|</a>
</Link>
<Link href="/|" as={`/|`}>
<a>|</a>
</Link>
import Router from "next/router";
const router = useRouter();
const { $1 } = router.query;
import Router, { withRouter } from "next/router";
import { useRouter } from "next/router";