@@ -4,28 +4,30 @@ import './index.css';
4
4
import App from './App' ;
5
5
import * as serviceWorker from './serviceWorker' ;
6
6
7
- let setStates = new Map ( ) ;
7
+ let HotContext = React . createContext ( ) ;
8
+ let _invalidate ;
9
+ function HotContainer ( { children } ) {
10
+ const [ inc , setInc ] = React . useState ( 0 ) ;
11
+ _invalidate = ( ) => setInc ( c => c + 1 ) ;
12
+ return < HotContext . Provider value = { inc } > { children } </ HotContext . Provider > ;
13
+ }
8
14
9
15
window . __enqueueForceUpdate = function ( type ) {
10
16
console . log ( 'force' , type . name ) ;
11
- const id = type . __hot__id ;
12
- ( setStates . get ( id ) || [ ] ) . forEach ( setState => setState ( { } ) ) ;
17
+ _invalidate ( ) ;
13
18
} ;
14
19
15
20
window . __renderHook = function ( type ) {
16
21
console . log ( 'render' , type . name ) ;
17
- const [ , setState ] = React . useState ( ) ;
18
- React . useLayoutEffect ( ( ) => {
19
- const id = type . __hot__id ;
20
- if ( ! setStates . has ( id ) ) {
21
- setStates . set ( id , new Set ( ) ) ;
22
- }
23
- setStates . get ( id ) . add ( setState ) ;
24
- return ( ) => setStates . get ( id ) . delete ( setState ) ;
25
- } , [ ] ) ;
22
+ React . useContext ( HotContext ) ;
26
23
} ;
27
24
28
- ReactDOM . render ( < App /> , document . getElementById ( 'root' ) ) ;
25
+ ReactDOM . render (
26
+ < HotContainer >
27
+ < App />
28
+ </ HotContainer > ,
29
+ document . getElementById ( 'root' )
30
+ ) ;
29
31
30
32
// If you want your app to work offline and load faster, you can change
31
33
// unregister() to register() below. Note this comes with some pitfalls.
0 commit comments