File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -240,12 +240,12 @@ class PhoneInput extends React.Component {
240
240
}
241
241
}
242
242
243
- UNSAFE_componentWillReceiveProps ( nextProps ) {
244
- if ( nextProps . country !== this . props . country ) {
245
- this . updateCountry ( nextProps . country ) ;
243
+ componentDidUpdate ( prevProps , prevState , snapshot ) {
244
+ if ( prevProps . country !== this . props . country ) {
245
+ this . updateCountry ( this . props . country ) ;
246
246
}
247
- else if ( nextProps . value !== this . props . value ) {
248
- this . updateFormattedNumber ( nextProps . value ) ;
247
+ else if ( prevProps . value !== this . props . value ) {
248
+ this . updateFormattedNumber ( this . props . value ) ;
249
249
}
250
250
}
251
251
Original file line number Diff line number Diff line change @@ -188,6 +188,26 @@ describe('correct value update', () => {
188
188
expect ( phoneInput . querySelector ( '.selected-flag' ) . children [ 0 ] . className ) . toBe ( 'flag 0' )
189
189
} )
190
190
191
+ test ( 'should rerender country without crashing' , ( ) => {
192
+ const { container : phoneInput , rerender } = render (
193
+ < PhoneInput
194
+ country = { undefined }
195
+ /> )
196
+
197
+ rerender (
198
+ < PhoneInput
199
+ country = "us"
200
+ /> )
201
+
202
+ rerender (
203
+ < PhoneInput
204
+ country = "es"
205
+ /> )
206
+
207
+ expect ( phoneInput . querySelector ( '.selected-flag' ) . children . length ) . toBe ( 1 )
208
+ expect ( phoneInput . querySelector ( '.selected-flag' ) . children [ 0 ] . className ) . toBe ( 'flag es' )
209
+ } )
210
+
191
211
it ( 'renders one prefix when updated from empty value' , ( ) => {
192
212
const { container : phoneInput , rerender } = render (
193
213
< PhoneInput
You can’t perform that action at this time.
0 commit comments