gistda-sphere-react

useSphere

Loading state of the Sphere API and the sphere namespace, without needing a map

useSphere reports whether the Sphere script has loaded, and gives you the global sphere namespace. It doesn't need a map.

import { useSphere } from "gistda-sphere-react";

function ApiStatus() {
  const { isLoaded, error } = useSphere();
  if (error) return <p>Couldn't load the map API: {error.message}</p>;
  return <p>{isLoaded ? "Map API ready" : "Loading…"}</p>;
}

Return value

PropertyTypeDescription
sphereSphereNamespace | nullThe global sphere namespace, once loaded.
isLoadedbooleantrue once the script has loaded.
errorError | nullWhy the script couldn't load, if it failed.
apiKeystringThe key given to SphereProvider.

Use the namespace for Sphere classes and enums, for example new sphere.Polygon(...) or sphere.Util.formatDistance(1500, "en"). For formatting and conversions with typed results, see useSphereUtils.

On this page