1
- # vscode -react-typescript
1
+ # swyx -react-typescript-snippets
2
2
3
- -------------------
3
+ ---
4
4
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.
6
8
7
9
## Installation
8
10
@@ -11,44 +13,84 @@ There you have either the option to show the already installed snippets or insta
11
13
12
14
Launch VS Code Quick Open (Ctrl + P or Cmd + P), paste the following command, and press enter.
13
15
14
- ` ext install vscode -react-typescript `
16
+ ` ext install swyx -react-typescript-snippets `
15
17
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'.
17
19
18
20
## Supported languages (file extensions)
19
21
20
- * TypeScript (.ts)
21
- * TypeScript React (.tsx)
22
+ - TypeScript (.ts)
23
+ - TypeScript React (.tsx)
22
24
23
25
## Snippets
24
26
25
27
Below is a list of all available snippets and the triggers of each one. The ** ⇥** means the ` TAB ` key.
26
28
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
+ ```
52
94
53
95
## License
54
96
0 commit comments