ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
29 lines • 1.01 kB
JavaScript
import { useCallback } from 'react';
import { useAddNotificationContext } from "./useAddNotificationContext.js";
/**
* Hook for Notification Side Effect
*
* @example
*
* const notify = useNotify();
* // simple message (info level)
* notify('Level complete');
* // specify level
* notify('A problem occurred', { type: 'error' })
* // pass arguments to the translation function
* notify('Deleted %{count} elements', { type: 'info', messageArgs: { smart_count: 23 } })
* // show the action as undoable in the notification
* notify('Post renamed', { type: 'info', undoable: true })
*/
export const useNotify = () => {
const addNotification = useAddNotificationContext();
return useCallback((message, options = {}) => {
const { type: messageType = 'info', ...notificationOptions } = options;
addNotification({
message,
type: messageType,
notificationOptions,
});
}, [addNotification]);
};
//# sourceMappingURL=useNotify.js.map