mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-18 14:27:51 +00:00
25 lines
521 B
TypeScript
25 lines
521 B
TypeScript
interface ShareData {
|
|
title: string;
|
|
text: string;
|
|
url: string;
|
|
}
|
|
|
|
export function useShare() {
|
|
const isShareSupported = typeof navigator !== 'undefined' && !!navigator.share;
|
|
|
|
const share = async (data: ShareData) => {
|
|
if (!isShareSupported) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await navigator.share(data);
|
|
} catch (error) {
|
|
if (error instanceof Error && error.name !== 'AbortError') {
|
|
console.error('Error sharing:', error);
|
|
}
|
|
}
|
|
};
|
|
|
|
return { share, isShareSupported };
|
|
} |