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
| Property | Type | Description |
|---|---|---|
sphere | SphereNamespace | null | The global sphere namespace, once loaded. |
isLoaded | boolean | true once the script has loaded. |
error | Error | null | Why the script couldn't load, if it failed. |
apiKey | string | The 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.