@@ -6,6 +6,7 @@ const AUTO_RENDER_COUNT = 5;
66
77class Page extends React . Component {
88 state = {
9+ action : null ,
910 type : null ,
1011 auto : false ,
1112 counter : 0 ,
@@ -21,6 +22,9 @@ class Page extends React.Component {
2122 input = null ;
2223 checkbox = null ;
2324
25+ clearButton = null ;
26+ renderButton = null ;
27+
2428 componentDidMount ( ) {
2529 this . props . load ( ( { block, differentBlocks } ) => {
2630 this . setState ( { block, differentBlocks } ) ;
@@ -29,42 +33,51 @@ class Page extends React.Component {
2933
3034 onRenderSameComponents = ( ) => {
3135 this . setState ( {
36+ action : 'render' ,
3237 type : 'SAME_COMOPNENT' ,
33- auto : false ,
38+ counter : this . state . auto ? ++ this . state . counter : this . state . counter ,
3439 } ) ;
3540 } ;
3641
3742 onRenderDifferentComponents = ( ) => {
3843 this . setState ( {
44+ action : 'render' ,
3945 type : 'DIFFERENT_COMOPNENTS' ,
40- auto : false ,
4146 } ) ;
4247 } ;
4348
4449 onAutoRender = ( ) => {
4550 this . setState ( {
46- type : 'SAME_COMOPNENT' ,
51+ action : 'autoRender' ,
52+ // type: 'SAME_COMOPNENT',
4753 auto : true ,
48- counter : ++ this . state . counter ,
4954 } ) ;
5055 } ;
5156
5257 onClear = ( ) => {
5358 this . setState ( {
59+ action : 'clear' ,
5460 type : null ,
55- auto : false ,
5661 } ) ;
5762 } ;
5863
5964 componentDidUpdate ( ) {
6065 if ( this . state . auto ) {
6166 if ( this . state . counter !== AUTO_RENDER_COUNT ) {
62- setTimeout ( ( ) => {
63- this . onClear ( ) ;
67+ if ( this . state . action === 'render' ) {
68+ // setTimeout to show visual re-render
6469 setTimeout ( ( ) => {
65- this . onAutoRender ( ) ;
66- } ) ;
67- } ) ;
70+ this . clearButton . click ( ) ;
71+ } , 500 ) ;
72+ } else if (
73+ this . state . action === 'clear' ||
74+ this . state . action === 'autoRender'
75+ ) {
76+ // setTimeout to show visual re-render
77+ setTimeout ( ( ) => {
78+ this . renderButton . click ( ) ;
79+ } , 500 ) ;
80+ }
6881 } else {
6982 this . setState ( {
7083 counter : 0 ,
@@ -117,8 +130,6 @@ class Page extends React.Component {
117130 ) ;
118131 }
119132
120- renderPerf ( ) { }
121-
122133 renderPage ( ) {
123134 if ( ! this . state . type ) {
124135 return (
@@ -227,9 +238,8 @@ class Page extends React.Component {
227238 < ScrollView width = "100%" flex = { 1 } >
228239 < Box center className = "controlls-space" >
229240 < button
230- disabled = {
231- ! this . state . block || this . state . type || this . state . counter !== 0
232- }
241+ ref = { el => ( this . renderButton = el ) }
242+ disabled = { ! this . state . block || this . state . type }
233243 onClick = { this . onRenderSameComponents }
234244 >
235245 Render 1000 same components
@@ -244,9 +254,7 @@ class Page extends React.Component {
244254 </ a >
245255
246256 < button
247- disabled = {
248- ! this . state . block || this . state . type || this . state . counter !== 0
249- }
257+ disabled = { ! this . state . block || this . state . type }
250258 onClick = { this . onRenderDifferentComponents }
251259 >
252260 Render 1000 different components
@@ -261,16 +269,15 @@ class Page extends React.Component {
261269 </ a >
262270
263271 < button
264- disabled = {
265- ! this . state . block || this . state . type || this . state . counter !== 0
266- }
272+ disabled = { ! this . state . block || this . state . type }
267273 onClick = { this . onAutoRender }
268274 >
269275 Render { AUTO_RENDER_COUNT } times
270276 </ button >
271277
272278 < button
273- disabled = { ! this . state . type || this . state . counter !== 0 }
279+ ref = { el => ( this . clearButton = el ) }
280+ disabled = { ! this . state . type }
274281 onClick = { this . onClear }
275282 >
276283 Clear
0 commit comments