File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
hooks/useDestructiveAction Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 11import { useCallback } from 'react' ;
22
3- import { useDestructiveActionStore } from './useDestructiveActionStore ' ;
3+ import type { Promisable } from 'type-fest ' ;
44
5- import type { DestructiveAction } from './useDestructiveActionStore' ;
5+ import { useDestructiveActionStore } from './useDestructiveActionStore' ;
66
7- export function useDestructiveAction ( destructiveAction : DestructiveAction ) {
7+ export function useDestructiveAction < TArgs extends any [ ] > ( destructiveAction : ( ... args : TArgs ) => Promisable < void > ) {
88 const addPendingDestructiveAction = useDestructiveActionStore ( ( store ) => store . addPendingDestructiveAction ) ;
9- return useCallback ( ( ) => {
10- addPendingDestructiveAction ( destructiveAction ) ;
11- } , [ destructiveAction , addPendingDestructiveAction ] ) ;
9+ return useCallback (
10+ ( ...args : TArgs ) => {
11+ addPendingDestructiveAction ( ( ) => destructiveAction ( ...args ) ) ;
12+ } ,
13+ [ destructiveAction , addPendingDestructiveAction ]
14+ ) ;
1215}
Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ type Story = StoryObj<typeof CoreProvider>;
1010
1111const Children = ( ) => {
1212 const addNotification = useNotificationsStore ( ( store ) => store . addNotification ) ;
13- const destructiveAction = useDestructiveAction ( ( ) => alert ( 'Delete' ) ) ;
13+ const destructiveAction = useDestructiveAction ( ( event : React . MouseEvent < HTMLButtonElement > ) => {
14+ alert ( `Delete at Event Time: ${ event . timeStamp } ` ) ;
15+ } ) ;
1416 return (
1517 < div >
1618 < Button
You can’t perform that action at this time.
0 commit comments