1- import React , { PureComponent } from 'react' ;
2- import { flushSync , createRoot } from 'react-dom' ;
3- import Scheduler from 'scheduler' ;
1+ import React , { PureComponent , unstable_startTransition } from 'react' ;
2+ import { unstable_createRoot } from 'react-dom' ;
43import _ from 'lodash' ;
54import Charts from './Charts' ;
65import Clock from './Clock' ;
@@ -55,19 +54,17 @@ class App extends PureComponent {
5554 return ;
5655 }
5756 if ( this . state . strategy !== 'async' ) {
58- flushSync ( ( ) => {
59- this . setState ( state => ( {
60- showDemo : ! state . showDemo ,
61- } ) ) ;
62- } ) ;
57+ this . setState ( state => ( {
58+ showDemo : ! state . showDemo ,
59+ } ) ) ;
6360 return ;
6461 }
6562 if ( this . _ignoreClick ) {
6663 return ;
6764 }
6865 this . _ignoreClick = true ;
6966
70- Scheduler . unstable_next ( ( ) => {
67+ unstable_startTransition ( ( ) => {
7168 this . setState ( { showDemo : true } , ( ) => {
7269 this . _ignoreClick = false ;
7370 } ) ;
@@ -76,9 +73,7 @@ class App extends PureComponent {
7673
7774 debouncedHandleChange = _ . debounce ( value => {
7875 if ( this . state . strategy === 'debounced' ) {
79- flushSync ( ( ) => {
80- this . setState ( { value : value } ) ;
81- } ) ;
76+ this . setState ( { value : value } ) ;
8277 }
8378 } , 1000 ) ;
8479
@@ -108,9 +103,9 @@ class App extends PureComponent {
108103 break ;
109104 case 'async' :
110105 // TODO: useTransition hook instead.
111- setTimeout ( ( ) => {
106+ unstable_startTransition ( ( ) => {
112107 this . setState ( { value} ) ;
113- } , 0 ) ;
108+ } ) ;
114109 break ;
115110 default :
116111 break ;
@@ -147,5 +142,5 @@ class App extends PureComponent {
147142}
148143
149144const container = document . getElementById ( 'root' ) ;
150- const root = createRoot ( container ) ;
145+ const root = unstable_createRoot ( container ) ;
151146root . render ( < App /> ) ;
0 commit comments