main
Branches
main (6.22.3)dev
Versions
6.22.3v4/5.xv3.x
useAsyncError

useAsyncError

Returns 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.

Docs and examples CC 4.0
Edit