Skip to content

Commit 4cd447f

Browse files
committed
Fix stale closure with onCopy
1 parent e8c5589 commit 4cd447f

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

packages/ui/src/components/ConfigureSSO/steps/TestConfigurationStep.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ const CopyTestUrlButton = ({ onTestRunCreated }: CopyTestUrlButtonProps): JSX.El
732732
.createEnterpriseConnectionTestRun(enterpriseConnection.id)
733733
.then(({ url }) => {
734734
setTestUrl(url);
735-
onCopy();
735+
onCopy(url);
736736
onTestRunCreated?.(url);
737737
})
738738
.catch(err => handleError(err as Error, [], card.setError))

packages/ui/src/hooks/useClipboard.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ export function useClipboard(text: string, optionsOrTimeout: number | UseClipboa
2727
const { timeout = 1500, ...copyOptions } =
2828
typeof optionsOrTimeout === 'number' ? { timeout: optionsOrTimeout } : optionsOrTimeout;
2929

30-
const onCopy = useCallback(() => {
31-
const didCopy = copy(text, copyOptions);
32-
setHasCopied(didCopy);
33-
}, [text, copyOptions]);
30+
const onCopy = useCallback(
31+
(overrideText?: string) => {
32+
const didCopy = copy(overrideText ?? text, copyOptions);
33+
setHasCopied(didCopy);
34+
},
35+
[text, copyOptions],
36+
);
3437

3538
useEffect(() => {
3639
let timeoutId: number | null = null;

0 commit comments

Comments
 (0)