![](/img/trans.png)
[英]Keep getting Unhandled promise rejection even with try catch block
[英]Web share api is throwing unhandled error on close even with try catch block included?
我只是想實現 web 共享 api,當我單擊按鈕時它可以工作,但每次我關閉它時它都會拋出未處理的錯誤。
以下是一些注意事項:
這是我的代碼:
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;
try catch 需要在異步 function 中。聲明 handleShareClick Async。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.