ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
33 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useNotify = void 0;
const react_1 = require("react");
const useAddNotificationContext_1 = require("./useAddNotificationContext.cjs");
/**
* 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 })
*/
const useNotify = () => {
const addNotification = (0, useAddNotificationContext_1.useAddNotificationContext)();
return (0, react_1.useCallback)((message, options = {}) => {
const { type: messageType = 'info', ...notificationOptions } = options;
addNotification({
message,
type: messageType,
notificationOptions,
});
}, [addNotification]);
};
exports.useNotify = useNotify;
//# sourceMappingURL=useNotify.js.map