Skip to content

avneesh0612/react-nextjs-snippets

Repository files navigation

React and Next.js Snippets README

React and Next.js Snippets with TypeScript support as well!πŸš€

Logo Showcase

React and Next.js Snippets - React and Next.js snippets with TypeScript | Product Hunt

Installation

  • Install the VSCode extension
  • Reload VSCode
  • Snippets are ready πŸŽ‰

Usage

React

JavaScript

  1. rimr (Import React)

    import React from "react";
  2. rimrd (Import ReactDOM)

    import ReactDOM from "react-dom";
  3. rimrs (Import React and useState)

    import React, { useState } from "react";
  4. rimrse (Import React, useState and useEffect)

    import React, { useState, useEffect } from "react";
  5. rfc (React functional component)

    const Component = () => { return <div></div>; }; export default Component;
  6. rue (React useEffect)

    useEffect(() => {}, []);
  7. rus (React useState)

    const [state, setState] = useState(initialValue);
  8. ruc (React useContext)

    const value = useContext(myContext);
  9. rur (React useRef)

    const refContainer = useRef(initialValue);

TypeScript

  1. rfcet (React functional component Typescript)

    import React from "react"; interface Props {} function Component({}: Props) { return <div></div>; } export default Component;

NextJS

JavaScript

  1. nssr (Next.js Get Server Side Props)

    export const getServerSideProps = async context => { return { props: {}, }; };
  2. nssg (Next.js Get Static Props)

    export const getStaticProps = async context => { return { props: {}, }; };
  3. ncapp (Next Custom App)

    const MyApp = ({ Component, pageProps }) => { return <Component {...pageProps} />; }; export default MyApp;
  4. ncdoc (Next Custom Document)

    import Document, { Html, Main, NextScript } from "next/_document"; const Document: Document = () => { return ( <Html lang="en"> <body> <Main /> <NextScript /> </body> </Html> ); }; export default Document;
  5. ngsp (Next.js Get Static Path Javascript)

    export const getStaticPaths = async () => { return { paths:[${1}], fallback:false }; }; 

TypeScript

  1. nssrt (Next.js Get Server Side Props Typescript)

    export const getServerSideProps: GetServerSideProps = async context => { return { props: {} }; };
  2. nssgt (Next.js Get Static Props Typescript)

    export const getStaticProps: getStaticProps = async context => { return { props: {} }; };
  3. ngip (Get Initial Props in Next.js)

    Page.getInitialProps = async context => { return { props: {} }; };
  4. npt (Next.js Page Typescript)

    import type { NextPage } from "next"; const Page: NextPage = () => { return <></>; }; export default Page;
  5. nct (Next.js Component Typescript)

    import type { NextComponentType, NextPageContext } from "next"; interface Props {} const Component: NextComponentType<NextPageContext, {}, Props> = ( props: Props ) => { return <div></div>; }; export default Component;
  6. ncappt (Next Custom App Typescript)

    const MyApp = ({ Component, pageProps }) => { return <Component {...pageProps} />; }; export default MyApp;
  7. ncdoct(Next Custom Document Typescript)

    import Document, { Html, Main, NextScript } from "next/_document"; const Document: Document = () => { return ( <Html lang="en"> <body> <Main /> <NextScript /> </body> </Html> ); }; export default Document;
  8. ngspt (Next.js Get Static Path Typescript)

    export const getStaticPaths: GetStaticPaths = async () => { return { paths:[${1}], fallback:false }; }