Files
react/components/utils/use-zeit-ui-context.ts
unix 935bd76e92 refactor: export all hooks functions directly from main module
refactor: rename the modules to make sure tree-shaking works
2020-05-16 00:24:05 +08:00

26 lines
737 B
TypeScript

import React from 'react'
import { ToastWithID } from '../use-toasts/toast-container'
export type UpdateToastsFunction<T> = (fn: (toasts: Array<T>) => Array<T>) => any
export interface ZeitUiContextParams {
toasts: Array<ToastWithID>
toastHovering: boolean
updateToasts: UpdateToastsFunction<ToastWithID>
updateToastHoverStatus: Function
}
const defaultParams: ZeitUiContextParams = {
toasts: [],
toastHovering: false,
updateToasts: t => t,
updateToastHoverStatus: () => {},
}
export const ZEITUIContent: React.Context<ZeitUiContextParams> = React.createContext<
ZeitUiContextParams
>(defaultParams)
export const useZEITUIContext = (): ZeitUiContextParams =>
React.useContext<ZeitUiContextParams>(ZEITUIContent)