File tree 3 files changed +19
-6
lines changed
3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -11,15 +11,22 @@ class SyncSelect extends Component {
11
11
options : [ ] ,
12
12
searchValue : '' ,
13
13
}
14
+
15
+ testOptions = options =>
16
+ typeof options === 'undefined' || options === null
17
+ ? [ ]
18
+ : options . map ( this . transform )
19
+
14
20
componentWillMount ( ) {
15
- const opts = this . props . options . map ( this . transform )
21
+ const opts = this . testOptions ( this . props . options )
22
+
16
23
this . setState ( {
17
24
sourceOptions : opts ,
18
25
options : this . computeOptions ( '' , opts ) ,
19
26
} )
20
27
}
21
28
componentWillReceiveProps ( nextProps ) {
22
- const newOpts = nextProps . options . map ( this . transform )
29
+ const newOpts = this . testOptions ( nextProps . options )
23
30
if ( this . props . sourceOptions !== newOpts ) {
24
31
this . setState ( {
25
32
sourceOptions : newOpts ,
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const createQuery = query =>
17
17
query === ''
18
18
? 'https://swapi.co/api/people'
19
19
: `https://swapi.co/api/people/?search=${ query } `
20
- const fakeApiCb = ( query , cb ) => fakeApi ( query ) . then ( r => cb ( null , r . results ) )
20
+ const fakeApiCb = ( query , cb ) => fakeApi ( query ) . then ( r => cb ( null , r ) )
21
21
const fakeApi = query =>
22
22
fetch ( createQuery ( query ) )
23
23
. then ( response => response . json ( ) )
@@ -34,7 +34,7 @@ storiesOf('Async', module)
34
34
transform = { data => ( { label : data . name , value : data . name } ) } >
35
35
< Label />
36
36
< List renderItem = { Item } />
37
- </ Container > ,
37
+ </ Container >
38
38
)
39
39
. add ( 'With promise' , ( ) =>
40
40
< Container
@@ -52,7 +52,7 @@ storiesOf('Async', module)
52
52
< List renderItem = { < Item render = { renderingItem } /> } />
53
53
</ div >
54
54
</ div >
55
- </ Container > ,
55
+ </ Container >
56
56
)
57
57
. add ( 'With custom debounce' , ( ) =>
58
58
< Container
@@ -69,5 +69,5 @@ storiesOf('Async', module)
69
69
< TagList renderTag = { Tag } />
70
70
< List renderItem = { < Item render = { renderingItem } /> } />
71
71
</ div >
72
- </ Container > ,
72
+ </ Container >
73
73
)
Original file line number Diff line number Diff line change @@ -88,6 +88,12 @@ storiesOf('Sync', module)
88
88
< List renderItem = { Item } />
89
89
</ Container >
90
90
)
91
+ . add ( 'Basic - Wraning on undefined options' , ( ) =>
92
+ < Container name = "context" onChange = { onChange } >
93
+ < Label />
94
+ < List renderItem = { Item } />
95
+ </ Container >
96
+ )
91
97
. add ( 'Basic withCustom Key' , ( ) =>
92
98
< Container
93
99
name = "context"
You can’t perform that action at this time.
0 commit comments