@exabytellc/utils
Version:
EB react utils to make everything a little easier!
21 lines (20 loc) • 787 B
JavaScript
import { handleTryCatchAsync } from "../_helpers/handleError";
/**
* Shares content using the Web Share API.
* @param {Object} options - The options for sharing.
* @param {string} options.title - Title of the content to share.
* @param {string} options.text - Description or more detailed text to share.
* @param {string} options.url - URL to share.
* @param {File[]} [options.files] - Files to share.
* @returns {Promise<boolean>} - A promise that resolves to true if the content was successfully shared; otherwise, false.
*/
export default async function share({ title, text, url, files }) {
return handleTryCatchAsync({
n: "share",
f: false,
e: async () => {
await navigator.share({ title, text, url, files });
return true;
}
});
}