Skip to content

Commit 62a0d0e

Browse files
doytchSunil Pai
authored andcommitted
Added React 16.3 lifecycle methods to sort-comp (#208)
* Added React 16 lifecycle methods to sort-comp * sort-comp: Use indexOf instead of includes
1 parent 5b2d124 commit 62a0d0e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

transforms/sort-comp.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,18 @@ const defaultMethodsOrder = [
117117
'state',
118118
'getInitialState',
119119
'getChildContext',
120+
'getDerivedStateFromProps',
120121
'componentWillMount',
122+
'UNSAFE_componentWillMount',
121123
'componentDidMount',
122124
'componentWillReceiveProps',
125+
'UNSAFE_componentWillReceiveProps',
123126
'shouldComponentUpdate',
124127
'componentWillUpdate',
128+
'UNSAFE_componentWillUpdate',
129+
'getSnapshotBeforeUpdate',
125130
'componentDidUpdate',
131+
'componentDidCatch',
126132
'componentWillUnmount',
127133
'/^on.+$/',
128134
'/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/',
@@ -135,6 +141,12 @@ const defaultMethodsOrder = [
135141
const regExpRegExp = /\/(.*)\/([g|y|i|m]*)/;
136142

137143
function selectorMatches(selector, method) {
144+
const methodName = method.key.name;
145+
146+
if ((method.static && selector === 'static-methods') && defaultMethodsOrder.indexOf(methodName) === -1) {
147+
return true;
148+
}
149+
138150
if (!method.value && method.typeAnnotation && selector === 'type-annotations') {
139151
return true;
140152
}
@@ -143,8 +155,6 @@ function selectorMatches(selector, method) {
143155
return true;
144156
}
145157

146-
const methodName = method.key.name;
147-
148158
if (selector === methodName) {
149159
return true;
150160
}

0 commit comments

Comments
 (0)