@@ -53,11 +53,17 @@ export function ToastProvider({
5353 payload : {
5454 id,
5555 component : options . component ,
56+ onShow : options . onShow ,
57+ onHide : options . onHide ,
5658 } ,
5759 } ) ;
5860
5961 total . set ( ( value ) => value + 1 ) ;
6062
63+ if ( options . onShow ) {
64+ options . onShow ( ) ;
65+ }
66+
6167 return id ;
6268 } ,
6369 [ total ]
@@ -69,14 +75,28 @@ export function ToastProvider({
6975 const hide = useCallback (
7076 ( ids ?: string | string [ ] ) => {
7177 if ( ids === undefined ) {
72- // Hide all toasts
78+ // Hide all toasts - call onHide for each toast before hiding
79+ toasts . forEach ( ( toast ) => {
80+ if ( toast . onHide ) {
81+ toast . onHide ( ) ;
82+ }
83+ } ) ;
7384 dispatch ( { type : 'HIDE_ALL' } ) ;
7485 heights . set ( { } ) ;
7586 total . set ( 0 ) ;
7687 } else {
77- // Hide specific toast(s)
88+ // Hide specific toast(s) - call onHide for each toast before hiding
7889 const idsArray = Array . isArray ( ids ) ? ids : [ ids ] ;
7990 const idsToRemove = idsArray ;
91+
92+ // Find and call onHide callbacks before removing
93+ idsToRemove . forEach ( ( id ) => {
94+ const toast = toasts . find ( ( t ) => String ( t . id ) === String ( id ) ) ;
95+ if ( toast ?. onHide ) {
96+ toast . onHide ( ) ;
97+ }
98+ } ) ;
99+
80100 dispatch ( {
81101 type : 'HIDE' ,
82102 payload : { ids : idsArray } ,
@@ -94,7 +114,7 @@ export function ToastProvider({
94114 total . set ( ( value ) => value - 1 ) ;
95115 }
96116 } ,
97- [ total , heights ]
117+ [ total , heights , toasts ]
98118 ) ;
99119
100120 const contextValue = useMemo < ToasterContextValue > (
0 commit comments