File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -76,11 +76,17 @@ export class MemoryGame extends Component {
76
76
}
77
77
}
78
78
79
+ componentWillReceiveProps ( nextProps ) {
80
+ if ( nextProps . cards !== this . props . cards ) {
81
+ this . resetGame ( nextProps . cards ) ;
82
+ }
83
+ }
84
+
79
85
getChildContext ( ) {
80
86
return {
81
87
[ MEMORY_GAME_CONTEXT ] : {
82
88
cards : this . getMemoryCards ( ) ,
83
- resetGame : this . resetGame ,
89
+ resetGame : this . resetGame . bind ( this , this . props . cards ) ,
84
90
movesCounter : this . state . moves ,
85
91
pairsFoundCounter : this . state . pairsFound ,
86
92
} ,
@@ -117,9 +123,9 @@ export class MemoryGame extends Component {
117
123
} ;
118
124
} ;
119
125
120
- resetGame = ( ) => {
126
+ resetGame = cards => {
121
127
clearTimeout ( this . timeout ) ;
122
- this . setState ( this . getInitialState ( this . props . cards ) , ( ) => {
128
+ this . setState ( this . getInitialState ( cards ) , ( ) => {
123
129
if ( this . props . glimpse ) {
124
130
this . startGlimpse ( ) ;
125
131
}
You can’t perform that action at this time.
0 commit comments