signoz/frontend/src/hooks/useNotifications.tsx
GermaVinsmoke 72452dc946
chore: remove react import (#2727)
* chore: added jsx-runtime plugin in eslint tsconfig

Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com>

* chore: updated react imports

Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com>

* chore: renamed redux dispatch

Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com>

* fix: build is fixed

---------

Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com>
Co-authored-by: Palash Gupta <palashgdev@gmail.com>
2023-05-19 13:14:32 +05:30

44 lines
1.0 KiB
TypeScript

import { notification } from 'antd';
import { NotificationInstance } from 'antd/es/notification/interface';
import { createContext, useContext, useMemo } from 'react';
type Notification = {
notifications: NotificationInstance;
};
const defaultNotification: Notification = {
notifications: {
success: (): void => {},
error: (): void => {},
info: (): void => {},
warning: (): void => {},
open: (): void => {},
destroy: (): void => {},
},
};
export const NotificationContext = createContext<Notification>(
defaultNotification,
);
export function NotificationProvider({
children,
}: {
children: JSX.Element;
}): JSX.Element {
const [notificationApi, NotificationElement] = notification.useNotification();
const notifications = useMemo(() => ({ notifications: notificationApi }), [
notificationApi,
]);
return (
<NotificationContext.Provider value={notifications}>
{NotificationElement}
{children}
</NotificationContext.Provider>
);
}
export const useNotifications = (): Notification =>
useContext(NotificationContext);