1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 07:26:36 +01:00
Whalebird-desktop-client-ma.../renderer/provider/unreads.tsx

30 lines
730 B
TypeScript

import { Dispatch, SetStateAction, createContext, useContext, useState } from 'react'
type UnreadsType = { [key: string]: number }
type Context = {
unreads: UnreadsType
setUnreads: Dispatch<SetStateAction<UnreadsType>>
}
const UnreadsContext = createContext<Context>({
unreads: {},
setUnreads: (_: UnreadsType) => {}
})
UnreadsContext.displayName = 'UnreadsContext'
export const useUnreads = () => {
return useContext(UnreadsContext)
}
type Props = {
children: React.ReactNode
}
export const UnreadsProvider: React.FC<Props> = ({ children }) => {
const [unreads, setUnreads] = useState<UnreadsType>({})
return <UnreadsContext.Provider value={{ unreads, setUnreads }}>{children}</UnreadsContext.Provider>
}