Skip to content

Commit 3ef6232

Browse files
author
sw-yx
committed
update with my snippets
1 parent 1476959 commit 3ef6232

File tree

3 files changed

+137
-347
lines changed

3 files changed

+137
-347
lines changed

README.md

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# vscode-react-typescript
1+
# swyx-react-typescript-snippets
22

3-
-------------------
3+
---
44

5-
This extension contains code snippets for React with Typescript.
5+
This extension contains code snippets for React with Typescript. It is a fork of https://github.com/infeng/vscode-react-typescript made by swyx.
6+
7+
It contains no class component APIs, assumes you use synthetic default imports, has hooks and subjectively better prop scaffolding.
68

79
## Installation
810

@@ -11,44 +13,84 @@ There you have either the option to show the already installed snippets or insta
1113

1214
Launch VS Code Quick Open (Ctrl + P or Cmd + P), paste the following command, and press enter.
1315

14-
`ext install vscode-react-typescript`
16+
`ext install swyx-react-typescript-snippets`
1517

16-
Alternatively you can open the extensions panel and search for 'Typescript React code snippets'.
18+
Alternatively you can open the extensions panel and search for 'swyx-react-typescript-snippets'.
1719

1820
## Supported languages (file extensions)
1921

20-
* TypeScript (.ts)
21-
* TypeScript React (.tsx)
22+
- TypeScript (.ts)
23+
- TypeScript React (.tsx)
2224

2325
## Snippets
2426

2527
Below is a list of all available snippets and the triggers of each one. The **** means the `TAB` key.
2628

27-
| Trigger | Content |
28-
| -------: | ------- |
29-
| `tsrcc→` | `class component skeleton` |
30-
| `tsrcfull→` | `class component skeleton with Props, State, and constructor` |
31-
| `tsrcjc→`| `class component skeleton without import and default export lines` |
32-
| `tsrpcc→`| `class purecomponent skeleton` |
33-
| `tsrpcjc→` | `class purecomponent without import and default export lines` |
34-
| `tsrpfc` | `pure function component skeleton` |
35-
| `tsrsfc` | `stateless functional component` |
36-
| `conc→` | `class default constructor with props and context` |
37-
| `cwm→` | `componentWillMount method` |
38-
| `ren→` | `render method` |
39-
| `cdm→` | `componentDidMount method` |
40-
| `cwrp→` | `componentWillReceiveProps method` |
41-
| `scu→` | `shouldComponentUpdate method` |
42-
| `cwu→` | `componentWillUpdate method` |
43-
| `cdu→` | `componentDidUpdate method` |
44-
| `cwum→` | `componentWillUnmount method` |
45-
| `gdsfp→` | `getDerivedStateFromProps method` |
46-
| `gsbu` | `getSnapshotBeforeUpdate method` |
47-
| `sst→` | `this.setState with object as parameter` |
48-
| `bnd→` | `binds the this of method inside the constructor` |
49-
| `met→` | `simple method` |
50-
| `tscntr→` | `react redux container skeleton` |
51-
| `imt` | `create a import` |
29+
| Trigger | Content |
30+
| ------: | ---------------------------------------------- |
31+
| `rfc→` | `create a react function component (no hooks)` |
32+
| `rhc→` | `create a react hooks component` |
33+
| `rsc→` | `create a react styeld component (no hooks)` |
34+
35+
```json
36+
{
37+
"React Function Component": {
38+
"prefix": "rfc",
39+
"body": [
40+
"export type ${1:IApp}Props = {$2",
41+
"}",
42+
"",
43+
"const $1: React.FC<$1Props> = ({ children }) => {",
44+
" return (",
45+
" ${0}",
46+
" )",
47+
"};",
48+
"",
49+
"export default $1;"
50+
],
51+
"description": "Create a React Function Component"
52+
},
53+
"React Hooks Component": {
54+
"prefix": "rhc",
55+
"body": [
56+
"export type ${1:IApp}Props = {$2",
57+
"}",
58+
"",
59+
"const $1: React.FC<$1Props> = ({ children }) => {",
60+
" const [${3}, set${3/(.*)/${3:/capitalize}/}] = React.useState($4);",
61+
" React.useEffect(() => {}, [])",
62+
" return (",
63+
" ${0}",
64+
" )",
65+
"};",
66+
"",
67+
"export default $1;"
68+
],
69+
"description": "Create a React Hooks Component."
70+
},
71+
"React Styled Component": {
72+
"prefix": "rsc",
73+
"body": [
74+
"const StyledDiv = styled('div')`",
75+
" border: 1px solid red",
76+
"`",
77+
"export type ${1:IApp}Props = {$2",
78+
"}",
79+
"",
80+
"const $1: React.FC<$1Props> = ({ children }) => {",
81+
" return (",
82+
" <StyledDiv>",
83+
" ${0}",
84+
" </StyledDiv>",
85+
" )",
86+
"};",
87+
"",
88+
"export default $1;"
89+
],
90+
"description": "Create a Styled React Component."
91+
}
92+
}
93+
```
5294

5395
## License
5496

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"name": "vscode-react-typescript",
3-
"version": "1.0.17",
4-
"description": "Code snippets for react in typescript",
5-
"displayName": "Typescript React code snippets",
6-
"publisher": "infeng",
2+
"name": "swyx-react-typescript-snippets",
3+
"version": "1.0.0",
4+
"description": "Code snippets for modern react in typescript",
5+
"displayName": "swyx-react-typescript-snippets",
6+
"publisher": "swyx",
77
"icon": "images/react.png",
88
"galleryBanner": {
99
"theme": "light"
1010
},
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/infeng/vscode-react-typescript.git"
13+
"url": "git+https://github.com/sw-yx/swyx-react-typescript-snippets.git"
1414
},
1515
"engines": {
1616
"vscode": "0.10.x"
@@ -27,9 +27,9 @@
2727
"author": "infeng",
2828
"license": "MIT",
2929
"bugs": {
30-
"url": "https://github.com/infeng/vscode-react-typescript/issues"
30+
"url": "https://github.com/sw-yx/swyx-react-typescript-snippets/issues"
3131
},
32-
"homepage": "https://github.com/infeng/vscode-react-typescript#readme",
32+
"homepage": "https://github.com/sw-yx/swyx-react-typescript-snippets#readme",
3333
"contributes": {
3434
"snippets": [
3535
{

0 commit comments

Comments
 (0)