This repository was archived by the owner on May 17, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -30,10 +30,11 @@ const withFontLoading = (fontName: string) => {
30
30
return (
31
31
OriginalComponent : React . ComponentType < * >
32
32
) : React . ComponentType < * > => {
33
- class WithFontLoading extends React . Component < * > {
33
+ class WithFontLoading extends React . Component < * , * > {
34
34
props : * ;
35
35
context: * ;
36
- state: * ;
36
+ state: { $fontStyles : { fontFamily : string } } ;
37
+ mounted: ?boolean ;
37
38
38
39
constructor ( props : any , context : any ) {
39
40
super ( props , context ) ;
@@ -48,18 +49,23 @@ const withFontLoading = (fontName: string) => {
48
49
}
49
50
50
51
componentDidMount ( ) {
52
+ this . mounted = true ;
51
53
if ( this . state . $fontStyles . fontFamily !== fontName ) {
52
- // $FlowFixMe
54
+ // $FlowFixMe (this can only be browser so will not be undefined)
53
55
loadFont ( `${ fontName } ` ) . then ( ( ) => {
54
- // $FlowFixMe
55
- this . setState ( { $fontStyles : { fontFamily : fontName } } ) ;
56
+ this . mounted &&
57
+ this . setState ( { $fontStyles : { fontFamily : fontName } } ) ;
56
58
} ) ;
57
59
}
58
60
}
59
61
60
62
render ( ) {
61
63
return < OriginalComponent { ...{ ...this . state , ...this . props } } /> ;
62
64
}
65
+
66
+ componentWillUnmount ( ) {
67
+ this . mounted = false ;
68
+ }
63
69
}
64
70
65
71
WithFontLoading . contextTypes = {
You can’t perform that action at this time.
0 commit comments