Tauri Core API - v2.6.0
    Preparing search index...

    Function listen

    • Listen to an emitted event to any target.

      Type Parameters

      • T

      Parameters

      • event: EventName

        Event name. Must include only alphanumeric characters, -, /, : and _.

      • handler: EventCallback<T>

        Event handler callback.

      • Optionaloptions: Options

        Event listening options.

      Returns Promise<UnlistenFn>

      A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

      import { listen } from '@tauri-apps/api/event';
      const unlisten = await listen<string>('error', (event) => {
      console.log(`Got error, payload: ${event.payload}`);
      });

      // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
      unlisten();

      1.0.0