-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript-react.snippets
More file actions
604 lines (592 loc) · 10.2 KB
/
javascript-react.snippets
File metadata and controls
604 lines (592 loc) · 10.2 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#https://gist.github.com/xavierartot/a29b1d65bc81f8e7f3ff8a9958635a72
snippet ic
import ${1:name} from './components/$1';
snippet ip
import PropTypes from 'prop-types';
snippet is
import ${1:name} from './screens/$1';
snippet il
import ${1:React} from '$1${0}';
snippet ia
import { ${1:action} } from '../actions/${0:file}';
snippet ilodash
import ${1:action} from 'lodash/$1';
snippet iredux
import { connect } from 'react-redux'
snippet ir
import React, { Component } from 'react';
snippet ri
import React, { Component } from 'react';
snippet ird
import ReactDOM from 'react-dom';
${0}
snippet ijpg
import './${1:filename}.jpg';
snippet ijpeg
import './${0:filename}.jpeg';
snippet ipng
import './${0:filename}.png';
snippet iimg
import './${0:filename.jpeg}';
snippet icss
import './${0:filename}.css';
snippet ird
import ReactDOM from 'react-dom';
${0}
snippet irr
import { ${1:Route} } from 'react-router-dom';
snippet ipt
import PropTypes from 'prop-types';
snippet iredux
import { createStore } from 'redux'
import { connect } from 'react-redux'
snippet inav
import { ${1:createBottomTabNavigator, createMaterialTopTabNavigator, createStackNavigator} } from 'react-navigation'
snippet iexpoi
import { ${1:FontAwesome, Ionicons} } from '${2:@expo/vector-icons}'
snippet iexpo
import { ${1:Constants} } from '${2:expo}'
snippet cdm
componentDidMount() {
${1}
}
snippet cdu
componentDidUpdate(prevProps){
${1}
}
snippet gdsfp
static getDerivedStateFromProps(nextProps, prevState){
if (this.state.visible === true && newProps.visible === false) {
registerLog('dialog is hidden');
}
return {
visible : nextProps.visible
};
}
snippet cdup
componentDidUpdate(prevProps, prevState) {
${1}
}
snippet cwm
componentWillMount() {
${1}
}
snippet cwr
componentWillReceiveProps(nextProps) {
${1}
}
snippet cwun
componentWillUnmount() {
${1}
}
snippet cwu
componentWillUpdate(nextProps, nextState) {
${1}
}
snippet fup
forceUpdate(${1:callback});
snippet dp
static defaultProps = {
${1}: ${2},
}
snippet pd
${1:Class}.defaultProps = {
${2:propsName}: PropTypes.${3:type},
}
snippet rcc
import React, { Component } from 'react';
class ${1:ClassName} extends Component {
render() {
return (
<div className='$1'>
$1
</div>
);
}
}
export default $1
snippet rcf
export default function ${1:className}(props) {
return (
${0}
);
}
snippet rfc
export default function ${1:className}(props) {
return (
${0}
);
}
snippet rsl
import React from 'react';
const ${1:className} = (${2:{props}}) => {
return (
<div className='$1'>
${0}
</div>
);
}
export default $1;
snippet rslf
const ${1:className} = (${2:props}) => {
return (
<div className='$1'>
${0}
</div>
);
}
export default ${1};
snippet rfsl
const ${1:className} = (props) => {
return (
<div className='$1'>
${0}
</div>
);
}
export default ${1};
snippet rdr
ReactDOM.render(${1}, ${2})
snippet ercc
export default class ${1:className} extends React.Component {
render() {
return (
<div>
${0:}
</div>
);
}
}
snippet ren
render() {
return (
<div>
${0:}
</div>
);
}
snippet rss
this.setState(() => ({
${2:variable} : ${0}
}))
snippet rsso
this.setState({
${0:variable}
})
snippet tssf
this.setState((currentState) => ({
${1:variable} : currentState.${0}
}))
snippet rso
this.state = {
${1} : ${0}
}
snippet sst
this.setState({
${1}: ${2}
});
snippet scu
shouldComponentUpdate(nextProps, nextState) {
${1}
}
snippet prp i
this.props.${1}
snippet rp
this.props${0}
snippet rcp i
const {${1}} = this.props
snippet ste i
this.state${0}
snippet st i
this.state${0}
snippet rts
this.state.${1}
snippet rs
state = {
${1}
}
snippet rpt
${1:component}.propTypes = {
${2:propName}: PropTypes.${3:type}.${4:isRequired},
${0}
}
snippet pt
${1:Class}.propTypes = {
${2:propsName}: PropTypes.${3:type},
}
snippet rrr
render() {
return (
<div>
${0:jsx}
</div>
);
}
snippet rcl
class ${1:MyComponent} extends React.Component {
render() {
return (
<div>
${2:jsx}
</div>
);
}
snippet rc
{/* ${0} */}
snippet rcj
{/* ${0} */}
snippet rcs
constructor(props) {
super(props);
this.state = {
${0}
}
}
snippet ref
ref={(${1:input}) => { this.${2:nameVar } = $1; }}
snippet roc
onClick={${1:this.}} ${0}
snippet ros
onSubmit={${1:this.}} ${0}
snippet roh
onHover={${1:this.}} ${0}
snippet rcn
className="${1}"
snippet rcla
className="${1:name}"
snippet re
on${1:Event}={${(e) => this.${2:function}}${0}
snippet rb
this.${1:method} = this.$1.bind(this);
snippet rbind
this.${1:method} = this.$1.bind(this);
snippet red
export default ${1};
snippet rfj
function(props) {
return (
<div>
{${1:props.}}
</div>
);
}
snippet rr
return (
<div>
{${0:props.}}
</div>
);
snippet rul
<ul className='${1:name class}'>
{
{${0:props.}
}
</ul>
snippet redc
export default class ${1} extends React.Component {
constructor(props) {
super(props);
this.state = {
${2}: ''
}
}
render() {
return (
<div></div>
);
}
}
snippet recc
export default class ${1} extends React.Component {
constructor(props) {
super(props);
this.state = {
${2}: ''
}
}
render() {
return (
<div></div>
);
}
}
snippet redcc
export default class ${1} extends React.Component {
constructor(props) {
super(props);
this.state = {
${2}: ''
}
}
render() {
return (
<div></div>
);
}
}
snippet ep
event.preventDefault()
snippet epd
event.preventDefault()
snippet rec
import React from 'react';
export const ${1:Name} = props => {
return {
render(
<div className="list$1">
<ul>
{this.props.map( element => <li key={element.toString()}>element</li>}
</ul>
</div>
)
}
}
snippet rm=>
${1:function_name} = (${2}) => {
${0}
}
snippet m=>
${1:function_name} = (${2}) => {
${0}
}
snippet rf
${1} = (event) => {
event.preventDefault()
${0}
}
snippet rf1
${1} = ${2} => ${0}
snippet rfl
${1} = ${2} => ${0}
snippet rfi
(${1}) => ${0}
#jsx with Emmet
snippet einput
input[type=text defaultValue=${2:val} placehoder=${3:val}]${0:Emmet}
snippet etextarea
textarea[placehoder=${3:val}]${0:Emmet}
snippet eselect
select>option[value=${1:val}]${0:Emmet}
snippet ebutton
button.btn.btn-primary[type=submit]${0:Emmet}
snippet rcsl
import React from 'react';
const ${1:name componemt} = ({${2:propsName}}) => (
<div>
{$2}
</div>
)
export default $1;
# wrap JSX with test in render() https://engineering.musefind.com/our-best-practices-for-writing-react-components-dec3eb5c3fc8
snippet riife
(() => {
if (${1:1}) {
${2:<div>$1</div>}
} else {
${0:<div>$2</div>}
}
})();
snippet rmap
{${1:array}.map( ${2:item} => <li key={$2.id}>{$2.id}</li> )}
snippet rmapl
{${1}.map( (${2:item}) => (
<li key={$2.id}>{$2.id}</li>
))}
#API Context
snippet racc
const Context = React.createContext()
#redux
snippet mstp
function mapStateToProps( { ${2:state} }${3: , props} ){
return {
$2${0:,}
}
}
export default connect(mapStateToProps)(${1})
snippet mstpwr
function mapStateToProps( { ${2:state} }${3: , props} ){
return {
$2: ${0}
}
}
export default withRouter(connect(mapStateToProps)(${1}))
snippet rdp
const { dispatch } = this.props
snippet rd
const { dispatch } = this.props
snippet connect
import { connect } from 'react-redux'
snippet l
let ${1} = ${0}
#REACT-NATIVE
snippet rnt
<Text>
${0}
</Text>
snippet rnv
<View>
${0}
</View>
snippet rnvt
<View>
<Text>
${0}
</Text>
</View>
snippet rncc
import React, { Component } from 'react';
import { View, Text } from 'react-native';
class ${1:ClassName} extends Component {
render() {
return (
<View>
<Text>
$1
</Text>
</View>
);
}
}
export default $1
snippet irn
import React, { Component } from 'react';
import { View, Text } from 'react-native';
snippet rj
return (
${0}
)
snippet rk
key={${0}}
#REACT CSS
snippet stylesheet
const styles = StyleSheet.create({
${1:container}: {
${0}
},
})
snippet ssc
const styles = StyleSheet.create({
${1:container}: {
${0}
},
})
snippet h
height: ${0},
snippet w
width: ${0},
snippet bgc
backgroundColor: '${0:#fff}',
snippet m
margin: ${0},
snippet fl
flex: 1,
snippet fd
flexDirection: '${0:row}',
snippet fdc
flexDirection: 'column',
snippet fdr
flexDirection: 'row',
snippet jc
justifyContent: '${0:center}',
snippet jcc
justifyContent: 'center',
snippet jcsb
justifyContent: 'space-between',
snippet jcsa
justifyContent: 'space-around',
snippet jcfe
justifyContent: 'flex-end',
snippet jcfs
justifyContent: 'flex-start',
snippet jcse
justifyContent: 'space-evenly',
snippet ai
alignItems: '${0:center}',
snippet aic
alignItems: 'center',
snippet aifs
alignItems: 'flex-start',
snippet aife
alignItems: 'flex-end',
snippet ais
alignItems: 'stretch',
snippet bdr
borderRadius: ${0:50},
snippet bdt
borderTop: ${0:1},
snippet bdr
borderRight: ${0:1},
snippet bdb
borderBottom: ${0:1},
snippet bdl
borderLeft: ${0:1},
snippet bdc
borderColor: ${0:red},
snippet bw
borderWidth: ${0:1},
snippet rstyl
style={styles.${0}}
snippet rstyle
style={styles.${0}}
snippet ra
alert(${0})
snippet fs
fontSize: ${0:20},
snippet pt
paddingTop: ${0:2},
snippet pr
paddingRight: ${0:2},
snippet pl
paddingLeft: ${0:2},
snippet pb
paddingBottom: ${0:2},
snippet mb
marginBottom: ${0:2},
snippet mt
marginTop: ${0:2},
snippet mr
marginRight: ${0:2},
snippet ml
marginLeft: ${0:2},
snippet asc
alignSelf: 'center',
snippet ass
alignSelf: 'strech',
snippet asfs
alignSelf: 'flex-start',
snippet asfe
alignSelf: 'flex-end',
snippet asb
alignSelf: 'baseline',
snippet ac
alignContent: 'stretch',
snippet acfs
alignContent: 'flex-start',
snippet acfe
alignContent: 'flex-end',
snippet acc
alignContent: 'center',
snippet acsb
alignContent: 'space-between',
snippet acsa
alignContent: 'space-around',
snippet rnstringify
JSON.stringify(${0})
snippet rstr
JSON.stringify(${0})
snippet rstring
JSON.stringify(${0})
snippet rparse
JSON.parse(${0})
snippet rv
{${0}}
snippet ttu
textTransform: 'uppercase'
snippet as
alignSelf: 'center',
snippet ttl
textTransform: 'lowercase'
snippet rno
${1}: {
${0}
},