I am simply trying to implement web share api, it works when I click the button, but everytime I close it it throws unhandled error.
Here are some notes:
Here is my code:
import React from 'react';
function Share() {
const handleShareClick = () => {
try {
navigator.share({
title: 'My App',
text: 'Check out this awesome app!',
url: 'https://my-app.com'
});
} catch (error: any) {
console.log(error);
}
};
return (
<div className="flex flex-col justify-center items-center w-full h-full p-2">
<h1>This is share page</h1>
<button className="bg-blue-500 p-4 text-white" onClick={handleShareClick}>
Share this app
</button>
</div>
);
}
export default Share;
A try catch needs to be in an async function. Declare the handleShareClick Async.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.