File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 1- import { useEffect , useState } from 'react' ;
1+ import { useSyncExternalStore } from 'react' ;
22import { DefaultToastOptions , Toast , ToastType } from './types' ;
33
44const TOAST_LIMIT = 20 ;
@@ -179,16 +179,19 @@ export const defaultTimeouts: {
179179} ;
180180
181181export const useStore = ( toastOptions : DefaultToastOptions = { } ) : State => {
182- const [ state , setState ] = useState < State > ( memoryState ) ;
183- useEffect ( ( ) => {
184- listeners . push ( setState ) ;
185- return ( ) => {
186- const index = listeners . indexOf ( setState ) ;
187- if ( index > - 1 ) {
188- listeners . splice ( index , 1 ) ;
189- }
190- } ;
191- } , [ state ] ) ;
182+ const state = useSyncExternalStore (
183+ ( callback ) => {
184+ listeners . push ( callback ) ;
185+ return ( ) => {
186+ const index = listeners . indexOf ( callback ) ;
187+ if ( index > - 1 ) {
188+ listeners . splice ( index , 1 ) ;
189+ }
190+ } ;
191+ } ,
192+ ( ) => memoryState ,
193+ ( ) => memoryState
194+ ) ;
192195
193196 const mergedToasts = state . toasts . map ( ( t ) => ( {
194197 ...toastOptions ,
You can’t perform that action at this time.
0 commit comments