@@ -110,32 +110,6 @@ export default class RNPickerSelect extends PureComponent {
110110 } ;
111111 }
112112
113- componentDidUpdate = ( prevProps , prevState ) => {
114- // update items if items or placeholder prop changes
115- const items = RNPickerSelect . handlePlaceholder ( {
116- placeholder : this . props . placeholder ,
117- } ) . concat ( this . props . items ) ;
118- const itemsChanged = ! isEqual ( prevState . items , items ) ;
119-
120- // update selectedItem if value prop is defined and differs from currently selected item
121- const { selectedItem, idx } = RNPickerSelect . getSelectedItem ( {
122- items,
123- key : this . props . itemKey ,
124- value : this . props . value ,
125- } ) ;
126- const selectedItemChanged =
127- ! isEqual ( this . props . value , undefined ) && ! isEqual ( prevState . selectedItem , selectedItem ) ;
128-
129- if ( itemsChanged || selectedItemChanged ) {
130- this . props . onValueChange ( selectedItem . value , idx ) ;
131-
132- this . setState ( {
133- ...( itemsChanged ? { items } : { } ) ,
134- ...( selectedItemChanged ? { selectedItem } : { } ) ,
135- } ) ;
136- }
137- } ;
138-
139113 constructor ( props ) {
140114 super ( props ) ;
141115
@@ -167,6 +141,32 @@ export default class RNPickerSelect extends PureComponent {
167141 this . renderInputAccessoryView = this . renderInputAccessoryView . bind ( this ) ;
168142 }
169143
144+ componentDidUpdate = ( prevProps , prevState ) => {
145+ // update items if items or placeholder prop changes
146+ const items = RNPickerSelect . handlePlaceholder ( {
147+ placeholder : this . props . placeholder ,
148+ } ) . concat ( this . props . items ) ;
149+ const itemsChanged = ! isEqual ( prevState . items , items ) ;
150+
151+ // update selectedItem if value prop is defined and differs from currently selected item
152+ const { selectedItem, idx } = RNPickerSelect . getSelectedItem ( {
153+ items,
154+ key : this . props . itemKey ,
155+ value : this . props . value ,
156+ } ) ;
157+ const selectedItemChanged =
158+ ! isEqual ( this . props . value , undefined ) && ! isEqual ( prevState . selectedItem , selectedItem ) ;
159+
160+ if ( itemsChanged || selectedItemChanged ) {
161+ this . props . onValueChange ( selectedItem . value , idx ) ;
162+
163+ this . setState ( {
164+ ...( itemsChanged ? { items } : { } ) ,
165+ ...( selectedItemChanged ? { selectedItem } : { } ) ,
166+ } ) ;
167+ }
168+ } ;
169+
170170 onUpArrow ( ) {
171171 const { onUpArrow } = this . props ;
172172
0 commit comments