import { useOnce, useMutable } from '../../react' import { scrollEvent } from './index' import { isF } from '../utils' import type { ReactNode } from 'react' import type { ScrollConfig, ScrollState } from './types' export const useScroll = (config: ScrollConfig) => { if (isF(config)) config = { scroll: config } const memo = useMutable(config) return useOnce(() => scrollEvent(memo as any)) } export default useScroll export interface ScrollProps extends Partial> { children: (state: ScrollState) => ReactNode } export const Scroll = (props: ScrollProps) => { const { children, ...other } = props return children(useScroll(other)) }