This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Pozzi
committed
Mar 13, 2021
1 parent
08e35e2
commit bd7b749
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |