useAsyncErrorReturns the rejection value from the nearest [<Await>][await] component.
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 />}
/>;
See the Deferred Data Guide and <Await> docs for more information.