2020-06-24 11:44:35 +00:00
|
|
|
import { IMessage } from "@saleor/components/messages";
|
2020-06-30 17:41:43 +00:00
|
|
|
import { IMessageContext, MessageContext } from "@saleor/components/messages";
|
|
|
|
import { useContext, useMemo } from "react";
|
|
|
|
|
|
|
|
export type UseNotifierResult = IMessageContext;
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
function useNotifier(): UseNotifierResult {
|
2020-06-30 17:41:43 +00:00
|
|
|
const notificationContext = useContext(MessageContext);
|
|
|
|
const notification = useMemo(() => notificationContext.current, [
|
|
|
|
notificationContext
|
|
|
|
]);
|
|
|
|
|
2020-06-24 11:44:35 +00:00
|
|
|
const notify = (options: IMessage) => {
|
2020-06-30 17:41:43 +00:00
|
|
|
notification.show(
|
|
|
|
options,
|
|
|
|
options.autohide && { timeout: options.autohide }
|
|
|
|
);
|
2020-06-24 11:44:35 +00:00
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
return notify;
|
|
|
|
}
|
|
|
|
export default useNotifier;
|