From 1d214a341230303dd1595bd7d7bd37dcdd0d18f5 Mon Sep 17 00:00:00 2001 From: SuperSuperDev Date: Tue, 18 Jan 2022 20:18:26 +0700 Subject: [PATCH] feat(snippets): add rcp, cxm, regc, igsp, isgsp --- .vscode/typescriptreact.code-snippets | 46 ++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/.vscode/typescriptreact.code-snippets b/.vscode/typescriptreact.code-snippets index cd6be9a..f1d1940 100644 --- a/.vscode/typescriptreact.code-snippets +++ b/.vscode/typescriptreact.code-snippets @@ -7,7 +7,7 @@ "React.useState": { "prefix": "us", "body": [ - "const [${1}, set${1/(^[a-zA-Z])(.*)/${1:/upcase}${2}/}] = React.useState<$1>(${2:initial${1/(^[a-zA-Z])(.*)/${1:/upcase}${2}/}})$0" + "const [${1}, set${1/(^[a-zA-Z])(.*)/${1:/upcase}${2}/}] = React.useState<$3>(${2:initial${1/(^[a-zA-Z])(.*)/${1:/upcase}${2}/}})$0" ] }, "React.useEffect": { @@ -39,6 +39,22 @@ "}" ] }, + "React Functional Component with Props": { + "prefix": "rcp", + "body": [ + "import * as React from 'react';\n", + "import clsxm from '@/lib/clsxm';\n", + "type ${1:${TM_FILENAME_BASE}}Props= {\n", + "} & React.ComponentPropsWithoutRef<'div'>\n", + "export default function ${1:${TM_FILENAME_BASE}}({className, ...rest}: ${1:${TM_FILENAME_BASE}}Props) {", + " return (", + "
", + " $0", + "
", + " )", + "}" + ] + }, //#endregion //*======== React =========== //#region //*=========== Commons =========== @@ -51,6 +67,14 @@ "//#endregion //*======== ${1} ===========" ] }, + "Region CSS": { + "prefix": "regc", + "body": [ + "/* #region /**=========== ${1} =========== */", + "${TM_SELECTED_TEXT}$0", + "/* #endregion /**======== ${1} =========== */" + ] + }, //#endregion //*======== Commons =========== //#region //*=========== Nextjs =========== @@ -80,7 +104,7 @@ "prefix": "napi", "body": [ "import { NextApiRequest, NextApiResponse } from 'next';\n", - "export default function ${1:${TM_FILENAME_BASE}}(req: NextApiRequest, res: NextApiResponse) {", + "export default async function ${1:${TM_FILENAME_BASE}}(req: NextApiRequest, res: NextApiResponse) {", " if (req.method === 'GET') {", " res.status(200).json({ name: 'Bambang' });", " } else {", @@ -92,7 +116,7 @@ "Get Static Props": { "prefix": "gsp", "body": [ - "export const getStaticProps: GetStaticProps = async (context) => {", + "export const getStaticProps = async (context: GetStaticPropsContext) => {", " return {", " props: {}", " };", @@ -115,13 +139,21 @@ "Get Server Side Props": { "prefix": "gssp", "body": [ - "export const getServerSideProps: GetServerSideProps = async (context) => {", + "export const getServerSideProps = async (context: GetServerSidePropsContext) => {", " return {", " props: {}", " };", "}" ] }, + "Infer Get Static Props": { + "prefix": "igsp", + "body": "InferGetStaticPropsType" + }, + "Infer Get Server Side Props": { + "prefix": "igssp", + "body": "InferGetServerSidePropsType" + }, "Import useRouter": { "prefix": "imust", "body": ["import { useRouter } from 'next/router';"] @@ -143,7 +175,11 @@ }, "Wrap with clsx": { "prefix": "cx", - "body": ["{clsx(${TM_SELECTED_TEXT})}"] + "body": ["{clsx(${TM_SELECTED_TEXT}$0)}"] + }, + "Wrap with clsxm": { + "prefix": "cxm", + "body": ["{clsxm(${TM_SELECTED_TEXT}$0, className)}"] } //#endregion //*======== Snippet Wrap =========== }