Skip to content

Instantly share code, notes, and snippets.

@mwafa
Created July 23, 2021 23:38
Show Gist options
  • Select an option

  • Save mwafa/73116dbce5b5398ef9dee9d07c37ef25 to your computer and use it in GitHub Desktop.

Select an option

Save mwafa/73116dbce5b5398ef9dee9d07c37ef25 to your computer and use it in GitHub Desktop.
Typescript dan Typescript-React User Snippet for Vscode
{
"Create Next Api": {
"prefix": "nextapi",
"body": [
"import { NextApiRequest, NextApiResponse } from \"next\"",
"export default async (req: NextApiRequest, res: NextApiResponse) => {",
" try {",
" switch (req.method) {",
" default:",
" throw new Error()",
" }",
" } catch (e) {",
" const code = e.code || 500",
" const message = e.code ? e.message : \"Something error!\"",
" return res.status(code).json({",
" error: true,",
" message,",
" })",
" }",
" }"
],
"description": "Create api element"
},
}
{
"Create Element and Interface": {
"prefix": "nextcomponent",
"body": [
"type ${1:$TM_FILENAME_BASE}Props = {}",
"",
"const ${1:$TM_FILENAME_BASE}: React.FC<${1:$TM_FILENAME_BASE}Props> = ({...props}) => {",
"",
" return ${0}",
"}",
"",
"${1:$TM_FILENAME_BASE}.defaultProps = {}",
"",
"export default ${1:$TM_FILENAME_BASE}"
],
"description": "Create element and interface"
},
"Create Element": {
"prefix": "nextsimplecomponent",
"body": [
"const ${1:$TM_FILENAME_BASE}: React.FC = () => {",
"",
" return ${0}",
"}",
"",
"export default ${1:$TM_FILENAME_BASE}"
],
"description": "Create element and interface"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment