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).
Type Parameters
Section titled “Type Parameters”M extends Record<string, any>
The top-level messages record for your application.
Returns
Section titled “Returns”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.
Type Parameters
Section titled “Type Parameters”N extends string | undefined = undefined
Optional namespace key inside M that will be used to scope
(prefix) message keys for notifications.
Parameters
Section titled “Parameters”options?
Section titled “options?”ConfigOptions<M> & object
Optional configuration.
Returns
Section titled “Returns”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.
Example
Section titled “Example”const { toast } = useTranslatedToast({ notificationsRoot: 'notifications' });toast.success({ key: 'success.saved' });Example
Section titled “Example”// In your library bootstrap:export const useTranslatedToast = createUseTranslatedToast<AppMessages>();