From 9098bdc7510ef1c390a6d34d71be42eda1cb476e Mon Sep 17 00:00:00 2001 From: asharonbaltazar Date: Wed, 7 Dec 2022 11:58:17 -0500 Subject: [PATCH] refactor: Change type to ensure notifs within state are Required<> --- frontend/components/context/Notifications/Notification.tsx | 2 +- .../context/Notifications/NotificationProvider.tsx | 6 ++++-- frontend/components/context/Notifications/Notifications.tsx | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/components/context/Notifications/Notification.tsx b/frontend/components/context/Notifications/Notification.tsx index 5afacc010f..0263a05c15 100644 --- a/frontend/components/context/Notifications/Notification.tsx +++ b/frontend/components/context/Notifications/Notification.tsx @@ -6,7 +6,7 @@ import classnames from "classnames"; import { Notification as NotificationType } from "./NotificationProvider"; interface NotificationProps { - notification: NotificationType; + notification: Required; clearNotification: (text: string) => void; } diff --git a/frontend/components/context/Notifications/NotificationProvider.tsx b/frontend/components/context/Notifications/NotificationProvider.tsx index 0f5c174d01..15287e9098 100644 --- a/frontend/components/context/Notifications/NotificationProvider.tsx +++ b/frontend/components/context/Notifications/NotificationProvider.tsx @@ -25,7 +25,9 @@ interface NotificationProviderProps { } const NotificationProvider = ({ children }: NotificationProviderProps) => { - const [notifications, setNotifications] = useState([]); + const [notifications, setNotifications] = useState[]>( + [] + ); const clearNotification = (text: string) => { return setNotifications((state) => @@ -44,7 +46,7 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => { return; } - const newNotification: Notification = { text, type, timeoutMs }; + const newNotification: Required = { text, type, timeoutMs }; return setNotifications((state) => [...state, newNotification]); }; diff --git a/frontend/components/context/Notifications/Notifications.tsx b/frontend/components/context/Notifications/Notifications.tsx index 9470327308..e0a9afbf24 100644 --- a/frontend/components/context/Notifications/Notifications.tsx +++ b/frontend/components/context/Notifications/Notifications.tsx @@ -2,7 +2,7 @@ import Notification from "./Notification"; import { Notification as NotificationType } from "./NotificationProvider"; interface NoticationsProps { - notifications: NotificationType[]; + notifications: Required[]; clearNotification: (text: string) => void; }