Skip to content
Tauri

once

once<T>(event, handler, options?): Promise<UnlistenFn>

Defined in: event.ts:157

Listens once to an emitted event to any target.

T

EventName

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

EventCallback<T>

Event handler callback.

Options

Event listening options.

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 { once } from '@tauri-apps/api/event';
interface LoadedPayload {
loggedIn: boolean,
token: string
}
const unlisten = await once<LoadedPayload>('loaded', (event) => {
console.log(`App is loaded, loggedIn: ${event.payload.loggedIn}, token: ${event.payload.token}`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

1.0.0


© 2025 Tauri Contributors. CC-BY / MIT