forked from welldone-software/why-did-you-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsx-test.tsx
153 lines (137 loc) · 4.2 KB
/
tsx-test.tsx
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
/* eslint-disable no-unused-vars */
import './types'
import React from 'react'
import * as Redux from 'react-redux'
import whyDidYouRender, { ExtraHookToTrack } from '.';
/* SHOULD ERROR because bad trackExtraHooks was provided (second argument should be string) */
whyDidYouRender(React, {trackExtraHooks: [[Redux, Redux.useSelector]]});
whyDidYouRender(React, {trackExtraHooks: [[Redux, 'useSelector']]});
interface Props {
str: string
}
const FunctionalComponent: React.FC<Props> = ({str}) => <div>{str}</div>
FunctionalComponent.whyDidYouRender = true
FunctionalComponent.whyDidYouRender = {collapseGroups: true}
/* SHOULD ERROR because we use an unsupported whyDidYouRender prop */
FunctionalComponent.whyDidYouRender = {nonWDYRProp: true}
/* SHOULD ERROR because whyDidYouRender shouldn't be a string */
FunctionalComponent.whyDidYouRender = 'a'
const MemoFunctionalComponent = React.memo<Props>(({str}) => <div>{str}</div>)
MemoFunctionalComponent.whyDidYouRender = true
MemoFunctionalComponent.whyDidYouRender = {collapseGroups: true}
/* SHOULD ERROR because we use an unsupported whyDidYouRender prop */
MemoFunctionalComponent.whyDidYouRender = {nonWDYRProp: true}
/* SHOULD ERROR because whyDidYouRender shouldn't be a string */
MemoFunctionalComponent.whyDidYouRender = 'a'
/* SHOULD ERROR because bad trackExtraHooks was provided (second argument should be string) */
FunctionalComponent.whyDidYouRender = {trackExtraHooks: [[Redux, Redux.useSelector]]}
FunctionalComponent.whyDidYouRender = {trackExtraHooks: [[Redux, 'useSelector']]}
class RegularClassComponent extends React.Component<Props>{
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ClassComponentWithBooleanWDYR extends React.Component<Props>{
static whyDidYouRender = true
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ClassComponentWithObjWDYR extends React.Component<Props>{
static whyDidYouRender = {collapseGroups: true}
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ErroredClassComponentWithNonWDYRProp extends React.Component<Props>{
/* SHOULD ERROR because we use an unsupported whyDidYouRender prop */
static whyDidYouRender = {nonWDYRProp: 'a'}
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ErroredClassComponentWithStringWDYR extends React.Component<Props>{
/* SHOULD ERROR because whyDidYouRender shouldn't be a string */
static whyDidYouRender = 'a'
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ErrorousClassComponentWithTrackExtraHooks extends React.Component<Props>{
static whyDidYouRender = {
collapseGroups: true,
/* SHOULD ERROR because bad trackExtraHooks was provided (second argument should be string) */
trackExtraHooks: [[Redux, Redux.useSelector] as ExtraHookToTrack]
}
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ClassComponentWithTrackExtraHooks extends React.Component<Props>{
static whyDidYouRender = {
collapseGroups: true,
trackExtraHooks: [[Redux, 'useSelector'] as ExtraHookToTrack]
}
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class PureClassComponentWithBooleanWDYR extends React.PureComponent<Props>{
static whyDidYouRender = true
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class PureClassComponentWithObjWDYR extends React.PureComponent<Props>{
static whyDidYouRender = {collapseGroups: true}
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ErroredPureClassComponentWithNonWDYRProp extends React.PureComponent<Props>{
/* SHOULD ERROR because we use an unsupported whyDidYouRender prop */
static whyDidYouRender = {nonWDYRProp: 'a'}
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}
class ErroredPureClassComponentWithStringWDYR extends React.PureComponent<Props>{
/* SHOULD ERROR because whyDidYouRender shouldn't be a string */
static whyDidYouRender = 'a'
render(){
const {str} = this.props
return (
<div>{str}</div>
)
}
}