2022-09-27 13:05:19 -07:00
|
|
|
import React, { createContext, useContext, useMemo, useState } from 'react';
|
|
|
|
|
|
|
|
type IStatContext = {
|
|
|
|
unreadChatsCount: number,
|
|
|
|
setUnreadChatsCount: React.Dispatch<React.SetStateAction<number>>
|
|
|
|
}
|
|
|
|
|
|
|
|
const StatContext = createContext<any>({
|
|
|
|
unreadChatsCount: 0,
|
|
|
|
});
|
|
|
|
|
2023-01-10 15:03:15 -08:00
|
|
|
interface IStatProvider {
|
|
|
|
children: React.ReactNode
|
|
|
|
}
|
|
|
|
|
|
|
|
const StatProvider: React.FC<IStatProvider> = ({ children }) => {
|
2022-09-27 13:05:19 -07:00
|
|
|
const [unreadChatsCount, setUnreadChatsCount] = useState<number>(0);
|
|
|
|
|
|
|
|
const value = useMemo(() => ({
|
|
|
|
unreadChatsCount,
|
|
|
|
setUnreadChatsCount,
|
|
|
|
}), [unreadChatsCount]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StatContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</StatContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const useStatContext = (): IStatContext => useContext(StatContext);
|
|
|
|
|
2022-12-06 22:45:10 -08:00
|
|
|
export { StatProvider, useStatContext, IStatContext };
|