UNPKG

@tarojsx/library

Version:
34 lines 953 B
import { useState } from 'react'; import { uuid } from '../utils'; /** * useGestureConfig hook. 获取 `react-use-gesture` 配置, 需要把返回的第二个参数赋值给包裹元素. * * @example * ```jsx * const [gestureConfig, containerProps] = useGestureConfig() * const bind = useDrag(() => {}, gestureConfig) * return ( * <View {...containerProps}>{ * <View {...bind()} /> * }</View> * ) * ``` */ export function useGestureConfig(options = {}) { const { id = uuid(), ref = () => { } } = options; const [container, setContainer] = useState(); const gestureConfig = { window: container, }; const containerProps = { id, ref: (container) => { if (!container) return; setContainer(container); ref(container); }, }; return [gestureConfig, containerProps]; } //# sourceMappingURL=useGestureConfig.js.map