Skip to content

Commit

Permalink
Refactor logic to decide returning <NotificationComponent /> or null.
Browse files Browse the repository at this point in the history
Centralize all `useNotificationMessage` related logic.
  • Loading branch information
kasperbirch1 committed Oct 19, 2023
1 parent f4e5619 commit 91a7cfa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/components/notification/NotificationComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from "react";
import PromoBar from "../promo-bar/PromoBar";

interface NotificationComponentProps {
notificationMessage: string | null;
notificationMessage: string;
}

const NotificationComponent: React.FC<NotificationComponentProps> = ({
notificationMessage
}) => {
if (!notificationMessage) return null;
return <PromoBar text={notificationMessage} type="info" />;
};

Expand Down
5 changes: 4 additions & 1 deletion src/core/utils/useNotificationMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const useNotificationMessage = ({
};

return [
() => <NotificationComponent notificationMessage={notificationMessage} />,
() =>
notificationMessage ? (
<NotificationComponent notificationMessage={notificationMessage} />
) : null,
handleNotificationMessage
];
};
Expand Down

0 comments on commit 91a7cfa

Please sign in to comment.