bigbuffet-rw/app/soapbox/contexts/stat-context.tsx

33 lines
800 B
TypeScript
Raw Normal View History

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 }) => {
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);
export { StatProvider, useStatContext, IStatContext };