Skip to content

createUseTranslatedToast

createUseTranslatedToast<M>(): <N>(options?) => object

Defined in: packages/sonner-next-intl/src/index.ts:45

Factory that creates a useTranslatedToast hook for a particular messages shape M. You should call this once per project/library where M represents the full messages object for your locale(s).

M extends Record<string, any>

The top-level messages record for your application.

A hook factory useTranslatedToast scoped to M.

<N>(options?): object

Hook that provides a toast object with methods adapted to translated messages.

The hook accepts an optional options object that mirrors ConfigOptions<M> and lets you provide a notificationsRoot namespace to prefix all message keys used for toast titles/descriptions.

N extends string | undefined = undefined

Optional namespace key inside M that will be used to scope (prefix) message keys for notifications.

ConfigOptions<M> & object

Optional configuration.

An object with the toast API bound.

toast: TranslatedToast<SubMessages<M, N>>

The final toast object that mirrors sonner but accepts typed TranslatedMessage descriptors. We use Object.assign to create a callable function (the default toast call) and attach the convenience methods.

const { toast } = useTranslatedToast({ notificationsRoot: 'notifications' });
toast.success({ key: 'success.saved' });
// In your library bootstrap:
export const useTranslatedToast = createUseTranslatedToast<AppMessages>();