admin-dashboard-web/src/Contexts/HeaderContext.js

30 lines
711 B
JavaScript

import { createContext, useContext, useState } from "react";
const preview = {
totalNotifications: 0,
notifications: [],
};
const HeaderContext = createContext(preview);
export const useHeaderContext = () => useContext(HeaderContext);
export default function HeaderProvider({ children }) {
const [totalNotifications, setTotalNotifications] = useState(0);
// initially null, then set to [...] on first fetch
const [notifications, setNotifications] = useState(null);
return (
<HeaderContext.Provider
value={{
totalNotifications,
setTotalNotifications,
notifications,
setNotifications,
}}
>
{children}
</HeaderContext.Provider>
);
}