Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
[#436] NotificationContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Pozzi committed Mar 13, 2021
1 parent 08e35e2 commit bd7b749
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/app/src/Context/NotificationContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React, { useState } from 'react';
import { INotificationMessage } from "../interfaces";

export interface NotificationContextType {
notification: INotificationMessage | null;
next: (notification: INotificationMessage) => void;
}

export const NotificationContext = React.createContext<NotificationContextType>({
notification: null,
next: () => {},
});

/**
* Visit https://reactjs.org/docs/context.html to read about how to implement and use the context in React.
*/
const NotificationContextProvider: React.FC<{}> = (props) => {
const [notification, setNotification] = useState<INotificationMessage | null>(null);

return (
<NotificationContext.Provider
value={{
notification: notification,
next: setNotification,
}}
>
{props.children}
</NotificationContext.Provider>
);
};

export { NotificationContextProvider };

0 comments on commit bd7b749

Please sign in to comment.