import { useMutable, useOnce } from '../../react' import { keyEvent } from './index' import { isF } from '../utils' import type { ReactNode } from 'react' import type { KeyArg, KeyState } from './types' export const useKey = (arg: KeyArg) => { if (isF(arg)) arg = { key: arg } const memo = useMutable(arg) return useOnce(() => keyEvent(memo as any)) } export interface KeyProps extends Partial> { children: (state: KeyState) => ReactNode } export const Key = (props: KeyProps) => { const { children, ...other } = props return children(useKey(other)) }