useAsyncError
傳回最接近的 [<Await>
][await] 元件的拒絕值。
import { useAsyncError, Await } from "react-router-dom";
function ErrorElement() {
const error = useAsyncError();
return (
<p>Uh Oh, something went wrong! {error.message}</p>
);
}
<Await
resolve={promiseThatRejects}
errorElement={<ErrorElement />}
/>;
請參閱 遞延資料指南 和 <Await>
文件 以取得更多資訊。