Skip to content

Commit f11a2dc

Browse files
authored
Merge pull request #68 from DouglasNeuroInformatics/dev
fix: allow params in destructive action
2 parents cdf4283 + 3af5c2d commit f11a2dc

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { 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
}

src/providers/CoreProvider/CoreProvider.stories.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type Story = StoryObj<typeof CoreProvider>;
1010

1111
const 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

0 commit comments

Comments
 (0)