YesPlayMusic/packages/web/hooks/useIpcRenderer.ts

14 lines
373 B
TypeScript
Raw Normal View History

import { IpcChannelsParams, IpcChannelsReturns } from '@/shared/IpcChannels'
import { useEffect } from 'react'
2022-05-01 19:53:25 +08:00
const useIpcRenderer = <T extends keyof IpcChannelsParams>(
channcel: T,
listener: (event: any, value: IpcChannelsReturns[T]) => void
) => {
useEffect(() => {
return window.ipcRenderer?.on(channcel, listener)
}, [])
}
export default useIpcRenderer