Skip to content

Commit

Permalink
refactor: Change type to ensure notifs within state are Required<>
Browse files Browse the repository at this point in the history
  • Loading branch information
asharonbaltazar committed Dec 7, 2022
1 parent 251426b commit 9098bdc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/components/context/Notifications/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from "classnames";
import { Notification as NotificationType } from "./NotificationProvider";

interface NotificationProps {
notification: NotificationType;
notification: Required<NotificationType>;
clearNotification: (text: string) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ interface NotificationProviderProps {
}

const NotificationProvider = ({ children }: NotificationProviderProps) => {
const [notifications, setNotifications] = useState<Notification[]>([]);
const [notifications, setNotifications] = useState<Required<Notification>[]>(
[]
);

const clearNotification = (text: string) => {
return setNotifications((state) =>
Expand All @@ -44,7 +46,7 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => {
return;
}

const newNotification: Notification = { text, type, timeoutMs };
const newNotification: Required<Notification> = { text, type, timeoutMs };

return setNotifications((state) => [...state, newNotification]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Notification from "./Notification";
import { Notification as NotificationType } from "./NotificationProvider";

interface NoticationsProps {
notifications: NotificationType[];
notifications: Required<NotificationType>[];
clearNotification: (text: string) => void;
}

Expand Down

0 comments on commit 9098bdc

Please sign in to comment.