@@ -36,11 +36,11 @@ interface State {
36
36
*/
37
37
intl ?: IntlShape ;
38
38
/**
39
- * list of memoized props we care about.
39
+ * list of memoized config we care about.
40
40
* This is important since creating intl is
41
41
* very expensive
42
42
*/
43
- prevProps : OptionalIntlConfig ;
43
+ prevConfig : OptionalIntlConfig ;
44
44
}
45
45
46
46
export type OptionalIntlConfig = Omit <
@@ -49,6 +49,21 @@ export type OptionalIntlConfig = Omit<
49
49
> &
50
50
Partial < typeof DEFAULT_INTL_CONFIG > ;
51
51
52
+ function filterIntlConfig < P extends OptionalIntlConfig = OptionalIntlConfig > (
53
+ config : P
54
+ ) : OptionalIntlConfig {
55
+ return {
56
+ locale : config . locale ,
57
+ timeZone : config . timeZone ,
58
+ formats : config . formats ,
59
+ textComponent : config . textComponent ,
60
+ messages : config . messages ,
61
+ defaultLocale : config . defaultLocale ,
62
+ defaultFormats : config . defaultFormats ,
63
+ onError : config . onError ,
64
+ } ;
65
+ }
66
+
52
67
export default class IntlProvider extends React . PureComponent <
53
68
OptionalIntlConfig ,
54
69
State
@@ -58,40 +73,19 @@ export default class IntlProvider extends React.PureComponent<
58
73
private cache : IntlCache = createIntlCache ( ) ;
59
74
state : State = {
60
75
cache : this . cache ,
61
- intl : undefined ,
62
- prevProps : {
63
- locale : this . props . locale ,
64
- } ,
76
+ intl : createIntl ( filterIntlConfig ( this . props ) ) ,
77
+ prevConfig : filterIntlConfig ( this . props ) ,
65
78
} ;
66
79
67
80
static getDerivedStateFromProps (
68
81
props : OptionalIntlConfig ,
69
- { prevProps , cache} : State
82
+ { prevConfig , cache} : State
70
83
) {
71
- const {
72
- locale,
73
- timeZone,
74
- formats,
75
- textComponent,
76
- messages,
77
- defaultLocale,
78
- defaultFormats,
79
- onError,
80
- } = props ;
81
- const filteredProps : OptionalIntlConfig = {
82
- locale,
83
- timeZone,
84
- formats,
85
- textComponent,
86
- messages,
87
- defaultLocale,
88
- defaultFormats,
89
- onError,
90
- } ;
91
- if ( ! shallowEquals ( prevProps , filteredProps ) ) {
84
+ const config = filterIntlConfig ( props ) ;
85
+ if ( ! shallowEquals ( prevConfig , config ) ) {
92
86
return {
93
- intl : createIntl ( filteredProps , cache ) ,
94
- prevProps : filteredProps ,
87
+ intl : createIntl ( config , cache ) ,
88
+ prevProps : config ,
95
89
} ;
96
90
}
97
91
return null ;
0 commit comments