Verwendung

Observe compass readings and stop when the screen unmounts.

tsx
// Observe compass readings and stop when the screen unmounts.
import { Text, onMount, signal, location, type EventSubscription } from 'kuito';

export function Compass() {
  const heading = signal('Waiting for compass');
  onMount(() => {
    let disposed = false;
    let subscription: EventSubscription | undefined;
    void location
      .watchHeading((value) => {
        heading.value = JSON.stringify(value);
      })
      .then((value) => {
        if (disposed) value.remove();
        else subscription = value;
      })
      .catch((error) => {
        heading.value = String(error);
      });
    return () => {
      disposed = true;
      subscription?.remove();
    };
  });
  return <Text>{heading.value}</Text>;
}

Typdeklaration

ts
export interface EventSubscription {
  remove(): void;
}

Mitglieder 1

NameTypErforderlichBeschreibung
remove() => voidJa—
remove — Methodensignaturen

Signaturen

ts
(): void

Parameter

Keine Parameter.

Rückgabe

void

Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.