npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reactnextjssnippets

v1.4.2

Published

React Snippets (ES6) tailored for Next.js apps

Downloads

4

Readme

React Snippets for Next.js by iJS

Thanks for giving this a go. Hope this helps and makes your coding more efficient and fun.

Hello.

Animations coming soon.

Pull requests for animations or any other contributions are most welcome!

Installation

  • 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!

Supported languages (file extensions)

  • 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.

Must have React Snippets

| Trigger | Content | | ----------: | ---------------------------------------- | | imr→ | Explicitely import React | | imrc→ | Import React { Component } | | imst→ | (16.8+) useState import | | ust→ | Use (16.8+) useState hook | | imeff→ | (16.8+) useEffect import | | 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 |

Next.js-specific Snippets

| Trigger | Content | | ------: | ----------- | | imhd→ | import Head | | nhd→ | Use Head |

Next.js getInitialProps()

| Trigger | Content | | -------: | --------------------------------------------------- | | gip→ | getInitialProps() outside component | | ccgip→ | static getInitialProps() inside class component | | gipaq→ | Next.js getInitialProps() withApollo() expose query |

Next.js getStaticProps()

| Trigger | Content | | ------: | ------------------------ | | gsp→ | exports getStaticProps() |

Next.js getServerSideProps()

| Trigger | Content | | ------: | ---------------------------- | | gssp→ | exports getServerSideProps() |

Next.js getStaticPaths()

| Trigger | Content | | ---------: | ------------------------ | | gspaths→ | exports getStaticPaths() |

Next.js Link

| Trigger | Content | | ----------: | --------------------------------- | | imlnk→ | import Link | | nlnk→ | Use Link | | nlnkpath→ | Next Link tag with pathname; | | nlnkdyn→ | Next Link tag with dynamic route; |

Next.js Router

| 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 | | nqprtr→ | Destructure Next.js query param from Router from useRouter |

  • More snippets to come, stay tuned!

Expanded Snippets

imr - Import React - if you must (Next.js imports React implicitly)

import React from "react";

imrc - Import React, Component

import { Component } from "react";

imst - Import { useState }

import { useState } from "react";

ust - React useState

  const [value, setValue] = useState(${1:INITIAL_VALUE});

imeff - Import { useEffect }

import { useEffect } from "react";

imctx - Import { useContext }

import { useContext } from "react";

uctx - React useContext

const | = useContext(|);';

immem - Import { useMemo }

import { useMemo } from "react";

imref - Import { useRef }

import { useRef } from "react";

imimphan - imImport { useImperativeHandle }

import { useImperativeHandle } from "react";

imlayeff - imImport { useLayoutEffect }

import { useLayoutEffect } from "react";

imdebval - imImport { useDebugValue }

import { useDebugValue } from "react";

imt - imImport PropTypes

import PropTypes from "prop-types";

impt - Import PropTypes

import PropTypes from "prop-types";

impc - Import PureComponent

import React, { PureComponent } from "react";

cc - Class Component

class | extends Component {
  state = { | }

  render() {
    return ( | );
  }
}

export default |;

ccc - Class Component With Constructor

class | extends React.Component {
    constructor(props) {
      super(props);
      this.state = { | }
    }
    render() {
        return ( | );
    }
}

export default |;

fc - Functional Component without a state

const | = props => {
  return ( | );
};

export default |;

fcst - Functional Component with a useState hook

import { useState } from 'react';

const | = props => {
  const [value, setValue] = useState(${1:INITIAL_VALUE});

  return ( | );
};

export default |;

imhd - import Next.js Head

import Head from "next/head";

nhd - Use Next.js Head

<Head> | </Head>

gip - getInitialProps() outside component

|.getInitialProps = ({ req }) => {
  return |
}

ccgip - getInitialProps() outside component

static async getInitialProps() { return { | }; }

gipaq - static getInitialProps() inside class component

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 };
}

gsp - exports getStaticProps()

export async function getStaticProps(context) {
  return {
    props: { | }, // will be passed to the page component as props
  }
}

gspaths - exports getStaticPaths()

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
  };
}

gssp - exports getServerSideProps()

export async function getServerSideProps(context) {
  return {
    props: {}, // will be passed to the page component as props
  };
}

imlnk - import Next.js Link

import Link from "next/link";

nlnk - Use Next.js Link

<Link href="|">
  <a>|</a>
</Link>

nlnkpath - Use Next.js Link With Pathname

<Link href={{ pathname: |, query: { queryName: | } }}>
  <a>|</a>
</Link>

nlnkdyn - Use Next.js LinkTagWithDynmicRoute

<Link href="/|" as={`/|`}>
  <a>|</a>
</Link>

imrtr - importNextRouter

import Router from "next/router";

nrtr - Next.js Router from useRouter

const router = useRouter();

nqprtr - Next.js query param from useRouter

const { $1 } = router.query;

imrtrwr - importNextRouterWithRouter

import Router, { withRouter } from "next/router";

imusrtr - importNextUseRouter

import { useRouter } from "next/router";

iJS.to