-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypescriptreact.hsnips
150 lines (112 loc) · 2.5 KB
/
typescriptreact.hsnips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
snippet imr "Import React from 'react'" b
import * as React from 'react'
endsnippet
snippet fce "function component export (with prop interface)" b
import * as React from 'react'
type $1Props = {
$3
}
export default function ${1:``rv = require('path').basename(path).split('.')[0]``}(${2:props}: $1Props) {
return ${4:null}$0
}
endsnippet
snippet sfce "simple function component export (no prop interface)" b
import * as React from 'react'
export default function ${1:``rv = require('path').basename(path).split('.')[0]``}() {
return ${2:null}
}
endsnippet
snippet provider "context/provider skeleton" b
import React, { createContext, ReactNode } from 'react';
export interface I${1:``rv = require('path').basename(path).split('.')[0]``}{
}
type $1Props = {
children: ReactNode;
};
export const $2Context = createContext<I$1>(null!);
const $1 = ({ children }: $1Props) => {
return (
<$2Context.Provider
value={{
$3
}}
>
{children}
</$2Context.Provider>
);
};
export default $1;
endsnippet
snippet uef "useEffect()" b
useEffect(() => {
$0
}, [$1])
endsnippet
snippet uefa "useEffect() async" b
useEffect(() => {
let cancelled = false;
(async function ${4:doWork}(): Promise<${5:void}> {
${1:// async work here}
if (cancelled) {
return
}
$2
})()
return () => {
cancelled = true
}
}, [$3])
endsnippet
snippet uec "useContext()" b
${5:const ${1:context} =} useContext$3($2)$0
endsnippet
snippet uem "useMemo(fn, inputs)" b
const ${1:memoized} = useMemo(() => ${2:{
$3
}}, [$4])
endsnippet
snippet impn "import { nested } from" b
import { $1 } from '$2'
endsnippet
snippet cl "console.log" w
console.log($1)
endsnippet
snippet clv "console.log variable" w
console.log('$1:', $1)
endsnippet
snippet rtf "React Test File" b
import React from 'react'
import { render } from '@testing-library/react'
import { ${1:``rv = require('path').basename(path).split('.')[0]``} } from '../$1'
describe('$1', () => {
it('should $2', () => {
$3
})
})
endsnippet
snippet rhtf "React Hooks Test File" b
import { renderHook } from '@testing-library/react-hooks'
import $2 from '../${1:``rv = require('path').basename(path).split('.')[0]``}'
describe('$1', () => {
it('should $3', () => {
$4
})
})
endsnippet
snippet desc "describe a test" b
describe('$1', () => {
it('should $2', () => {
$3
})
})
endsnippet
snippet it "create a test block" b
it('should $1', () => {
$2
})
endsnippet
snippet ait "create an async test block" b
it('should $1', async () => {
$2
})
endsnippet