1
1
import React , { Component } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
+ import { polyfill } from 'react-lifecycles-compat' ;
3
4
import classNames from 'classnames' ;
4
5
import Select from '../select' ;
5
6
import Cascader from '../cascader' ;
@@ -10,10 +11,22 @@ const { bindCtx } = func;
10
11
const { pickOthers } = obj ;
11
12
const { getStyle } = dom ;
12
13
14
+ const normalizeValue = value => {
15
+ if ( value ) {
16
+ if ( Array . isArray ( value ) ) {
17
+ return value ;
18
+ }
19
+
20
+ return [ value ] ;
21
+ }
22
+
23
+ return [ ] ;
24
+ } ;
25
+
13
26
/**
14
27
* CascaderSelect
15
28
*/
16
- export default class CascaderSelect extends Component {
29
+ class CascaderSelect extends Component {
17
30
static propTypes = {
18
31
prefix : PropTypes . string ,
19
32
pure : PropTypes . bool ,
@@ -266,7 +279,7 @@ export default class CascaderSelect extends Component {
266
279
super ( props , context ) ;
267
280
268
281
this . state = {
269
- value : this . normalizeValue (
282
+ value : normalizeValue (
270
283
'value' in props ? props . value : props . defaultValue
271
284
) ,
272
285
searchValue : '' ,
@@ -291,31 +304,17 @@ export default class CascaderSelect extends Component {
291
304
] ) ;
292
305
}
293
306
294
- componentWillReceiveProps ( nextProps ) {
307
+ static getDerivedStateFromProps ( props ) {
295
308
const st = { } ;
296
309
297
- if ( 'value' in nextProps ) {
298
- st . value = this . normalizeValue ( nextProps . value ) ;
310
+ if ( 'value' in props ) {
311
+ st . value = normalizeValue ( props . value ) ;
299
312
}
300
- if ( 'visible' in nextProps ) {
301
- st . visible = nextProps . visible ;
313
+ if ( 'visible' in props ) {
314
+ st . visible = props . visible ;
302
315
}
303
316
304
- if ( Object . keys ( st ) . length ) {
305
- this . setState ( st ) ;
306
- }
307
- }
308
-
309
- normalizeValue ( value ) {
310
- if ( value ) {
311
- if ( Array . isArray ( value ) ) {
312
- return value ;
313
- }
314
-
315
- return [ value ] ;
316
- }
317
-
318
- return [ ] ;
317
+ return st ;
319
318
}
320
319
321
320
updateCache ( dataSource ) {
@@ -917,3 +916,5 @@ export default class CascaderSelect extends Component {
917
916
return < Select { ...props } { ...others } /> ;
918
917
}
919
918
}
919
+
920
+ export default polyfill ( CascaderSelect ) ;
0 commit comments