import React, { createContext, useContext, useMemo, useState } from 'react'; type IStatContext = { unreadChatsCount: number, setUnreadChatsCount: React.Dispatch> } const StatContext = createContext({ unreadChatsCount: 0, }); const StatProvider: React.FC = ({ children }) => { const [unreadChatsCount, setUnreadChatsCount] = useState(0); const value = useMemo(() => ({ unreadChatsCount, setUnreadChatsCount, }), [unreadChatsCount]); return ( {children} ); }; const useStatContext = (): IStatContext => useContext(StatContext); export { StatProvider, useStatContext, IStatContext };