File tree Expand file tree Collapse file tree 4 files changed +36
-20
lines changed Expand file tree Collapse file tree 4 files changed +36
-20
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,5 @@ ReactDOM.createRoot(document.getElementById('root')).render(
8
8
< App />
9
9
</ React . StrictMode >
10
10
)
11
+
12
+ // ReactDOM.createRoot(document.getElementById('root')).render(<App />)
Original file line number Diff line number Diff line change @@ -103,14 +103,24 @@ export function useTransition(
103
103
} )
104
104
105
105
// Destroy all transitions on dismount.
106
- useOnce ( ( ) => ( ) => {
106
+ useOnce ( ( ) => {
107
107
each ( usedTransitions . current ! , t => {
108
- if ( t . expired ) {
109
- clearTimeout ( t . expirationId ! )
108
+ t . ctrl . ref ?. add ( t . ctrl )
109
+ const change = changes . get ( t )
110
+ if ( change ) {
111
+ t . ctrl . start ( change . payload )
110
112
}
111
- detachRefs ( t . ctrl , ref )
112
- t . ctrl . stop ( true )
113
113
} )
114
+
115
+ return ( ) => {
116
+ each ( usedTransitions . current ! , t => {
117
+ if ( t . expired ) {
118
+ clearTimeout ( t . expirationId ! )
119
+ }
120
+ detachRefs ( t . ctrl , ref )
121
+ t . ctrl . stop ( true )
122
+ } )
123
+ }
114
124
} )
115
125
116
126
// Keys help with reusing transitions between renders.
Original file line number Diff line number Diff line change 1
1
import { useState } from 'react'
2
- import { useOnce } from './useOnce '
2
+ import { useIsMounted } from './useIsMounted '
3
3
4
4
/** Return a function that re-renders this component, if still mounted */
5
5
export function useForceUpdate ( ) {
6
6
const update = useState < any > ( ) [ 1 ]
7
- const mounted = useState ( makeMountedRef ) [ 0 ]
8
- useOnce ( mounted . unmount )
7
+ const isMounted = useIsMounted ( )
9
8
return ( ) => {
10
- if ( mounted . current ) {
11
- update ( { } )
9
+ if ( isMounted . current ) {
10
+ update ( Math . random ( ) )
12
11
}
13
12
}
14
13
}
15
-
16
- function makeMountedRef ( ) {
17
- const mounted = {
18
- current : true ,
19
- unmount : ( ) => ( ) => {
20
- mounted . current = false
21
- } ,
22
- }
23
- return mounted
24
- }
Original file line number Diff line number Diff line change
1
+ import { useRef } from 'react'
2
+ import { useLayoutEffect } from './useLayoutEffect'
3
+
4
+ export const useIsMounted = ( ) => {
5
+ const isMounted = useRef ( false )
6
+ useLayoutEffect ( ( ) => {
7
+ isMounted . current = true
8
+
9
+ return ( ) => {
10
+ isMounted . current = false
11
+ }
12
+ } , [ ] )
13
+
14
+ return isMounted
15
+ }
You can’t perform that action at this time.
0 commit comments