From 490d84fe341f114a946ea18f1e70cf40d8c34bc9 Mon Sep 17 00:00:00 2001 From: asifrahaman13 Date: Tue, 25 Jun 2024 14:33:10 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20feat:=20implemented=20error=20state?= =?UTF-8?q?=20for=20backend=20socket=20connection=20and=20other=20failures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/javascript-snippets.md | 178 +++++++++++++++++++++++++++++++ docs/typescript-snippets.md | 202 ++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+) create mode 100644 docs/javascript-snippets.md create mode 100644 docs/typescript-snippets.md diff --git a/docs/javascript-snippets.md b/docs/javascript-snippets.md new file mode 100644 index 0000000..2400829 --- /dev/null +++ b/docs/javascript-snippets.md @@ -0,0 +1,178 @@ + +# Javascript snippets + +- `np` - nextPage +- `npssp` - nextPageServerSideProps +- `npsp` - nextPageStaticProps +- `npspth` - nextPageStaticPaths +- `nssp` - nextServerSideProps +- `nsp` - nextStaticProps +- `nspth` - nextStaticPaths +- `nip` - nextInitialProps +- `nimg` - nextImage +- `napp` - nextApp +- `ndoc` - nextDocument +- `napi` - nextApi +- `nmid` - nextMiddleware + +## `np` - nextPage + +```javascript +const FileName = ({}) => { + return
+} + +export default FileName +``` + +## `npssp` - nextPageServerSideProps + +```javascript +const FileName = ({}) => { + return
+} + +export const getServerSideProps = async (ctx) => { + return { + props: {} + } +} + +export default FileName +``` + +## `npsp` - nextPageStaticProps + +```javascript +const FileName = ({}) => { + return
+} + +export const getStaticProps = async (ctx) => { + return { + props: {}, + } +} + +export default FileName +``` + +## `npspth` - nextPageStaticPaths + +```javascript +const FileName = ({}) => { + return
+} + +export const getStaticPaths = async () => { + return { + paths: [], + fallback: false, + } +} + +export default FileName +``` + +## `nssp` - nextServerSideProps + +```javascript +export const getServerSideProps = async (ctx) => { + return { + props: {} + } +} +``` + +## `nsp` - nextStaticProps + +```javascript +export const getStaticProps = async (ctx) => { + return { + props: {}, + } +} +``` + +## `nspth` - nextStaticPaths + +```javascript +export const getStaticPaths = async () => { + return { + paths: [], + fallback: false, + } +} +``` + +## `nip` - nextInitialProps + +```javascript +FileName.getInitialProps = async (ctx) => { + return { + + } +} +``` + +## `nimg` - nextImage + +```javascript + +``` + +## `napp` - nextApp + +```javascript +export default function MyApp({ Component, pageProps }) { + return +} +``` + +## `ndoc` - nextDocument + +```javascript +import Document, { Html, Head, Main, NextScript } from 'next/document' + +class MyDocument extends Document { + static async getInitialProps(ctx) { + const initialProps = await Document.getInitialProps(ctx) + return { ...initialProps } + } + + render() { + return ( + + + +
+ + + + ); + } +} + +export default MyDocument +``` + +## `napi` - nextApi + +```javascript +export default async function handler(req, res) { + +} +``` + +## `nmid` - nextMiddleware + +```javascript +import { NextResponse } from 'next/server' +export async function middleware(request) { + +} + +export const config = { + matcher: '/about/:path*', +} +``` diff --git a/docs/typescript-snippets.md b/docs/typescript-snippets.md new file mode 100644 index 0000000..ee64afe --- /dev/null +++ b/docs/typescript-snippets.md @@ -0,0 +1,202 @@ + +# Typescript snippets + +- `np` - nextPage +- `npssp` - nextPageServerSideProps +- `npsp` - nextPageStaticProps +- `npspth` - nextPageStaticPaths +- `nssp` - nextServerSideProps +- `nsp` - nextStaticProps +- `nspth` - nextStaticPaths +- `nip` - nextInitialProps +- `nimg` - nextImage +- `napp` - nextApp +- `ndoc` - nextDocument +- `napi` - nextApi +- `nmid` - nextMiddleware + +## `np` - nextPage + +```typescript +import { NextPage } from 'next' + +interface Props {} + +const FileName: NextPage = ({}) => { + return
+} + +export default FileName +``` + +## `npssp` - nextPageServerSideProps + +```typescript +import { NextPage, GetServerSideProps } from 'next' + +interface Props {} + +const FileName: NextPage = ({}) => { + return
+} + +export const getServerSideProps: GetServerSideProps = async (ctx) => { + return { + props: {} + } +} + +export default FileName +``` + +## `npsp` - nextPageStaticProps + +```typescript +import { NextPage, GetStaticProps } from 'next' + +interface Props {} + +const FileName: NextPage = ({}) => { + return
+} + +export const getStaticProps: GetStaticProps = async (ctx) => { + return { + props: {}, + } +} + +export default FileName +``` + +## `npspth` - nextPageStaticPaths + +```typescript +import { NextPage, GetStaticPaths } from 'next' + +interface Props {} + +const FileName: NextPage = ({}) => { + return
+} + +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: [], + fallback: false, + } +} + +export default FileName +``` + +## `nssp` - nextServerSideProps + +```typescript +export const getServerSideProps: GetServerSideProps = async (ctx) => { + return { + props: {} + } +} +``` + +## `nsp` - nextStaticProps + +```typescript +export const getStaticProps: GetStaticProps = async (ctx) => { + return { + props: {}, + } +} +``` + +## `nspth` - nextStaticPaths + +```typescript +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: [], + fallback: false, + } +} +``` + +## `nip` - nextInitialProps + +```typescript +FileName.getInitialProps = async (ctx) => { + return { + + } +} +``` + +## `nimg` - nextImage + +```typescript + +``` + +## `napp` - nextApp + +```typescript +import type { AppProps } from 'next/app' + +export default function MyApp({ Component, pageProps }: AppProps) { + return +} +``` + +## `ndoc` - nextDocument + +```typescript +import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document' + +class MyDocument extends Document { + static async getInitialProps(ctx: DocumentContext) { + const initialProps = await Document.getInitialProps(ctx) + return { ...initialProps } + } + + render() { + return ( + + + +
+ + + + ); + } +} + +export default MyDocument +``` + +## `napi` - nextApi + +```typescript +import type { NextApiRequest, NextApiResponse } from 'next' + +interface Data {} + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + +} +``` + +## `nmid` - nextMiddleware + +```typescript +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' + +export async function middleware(request: NextRequest) { + +} + +export const config = { + matcher: '/about/:path*', +} +```