File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
- import { useEffect , useState } from 'react' ;
1
+ import { useEffect , useState , useRef } from 'react' ;
2
2
import { DefaultToastOptions , Toast , ToastType } from './types' ;
3
3
4
4
const TOAST_LIMIT = 20 ;
@@ -143,15 +143,21 @@ export const defaultTimeouts: {
143
143
144
144
export const useStore = ( toastOptions : DefaultToastOptions = { } ) : State => {
145
145
const [ state , setState ] = useState < State > ( memoryState ) ;
146
+ const initial = useRef ( memoryState ) ;
147
+
148
+ // TODO: Switch to useSyncExternalStore when targeting React 18+
146
149
useEffect ( ( ) => {
150
+ if ( initial . current !== memoryState ) {
151
+ setState ( memoryState ) ;
152
+ }
147
153
listeners . push ( setState ) ;
148
154
return ( ) => {
149
155
const index = listeners . indexOf ( setState ) ;
150
156
if ( index > - 1 ) {
151
157
listeners . splice ( index , 1 ) ;
152
158
}
153
159
} ;
154
- } , [ state ] ) ;
160
+ } , [ ] ) ;
155
161
156
162
const mergedToasts = state . toasts . map ( ( t ) => ( {
157
163
...toastOptions ,
You can’t perform that action at this time.
0 commit comments