source: imaps-frontend/node_modules/@use-gesture/react/src/useRecognizers.ts

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[d565449]1/* eslint-disable react-hooks/exhaustive-deps */
2import React from 'react'
3import { Controller } from '@use-gesture/core'
4import { GenericOptions, GestureKey, InternalHandlers, NativeHandlers } from '@use-gesture/core/types'
5import { ReactDOMAttributes } from './types'
6
7type HookReturnType<Config extends GenericOptions> = Config['target'] extends object
8 ? void
9 : (...args: any[]) => ReactDOMAttributes
10
11/**
12 * Utility hook called by all gesture hooks and that will be responsible for
13 * the internals.
14 *
15 * @param {InternalHandlers} handlers
16 * @param {GenericOptions} config
17 * @param {GestureKey} gestureKey
18 * @param {NativeHandler} nativeHandlers
19 * @returns nothing when config.target is set, a binding function when not.
20 */
21export function useRecognizers<Config extends GenericOptions>(
22 handlers: InternalHandlers,
23 config: Config | {} = {},
24 gestureKey?: GestureKey,
25 nativeHandlers?: NativeHandlers
26): HookReturnType<Config> {
27 const ctrl = React.useMemo(() => new Controller(handlers), [])
28 ctrl.applyHandlers(handlers, nativeHandlers)
29 ctrl.applyConfig(config, gestureKey)
30
31 React.useEffect(ctrl.effect.bind(ctrl))
32
33 React.useEffect(() => {
34 return ctrl.clean.bind(ctrl)
35 }, [])
36
37 // When target is undefined we return the bind function of the controller which
38 // returns prop handlers.
39 // @ts-ignore
40 if (config.target === undefined) {
41 return ctrl.bind.bind(ctrl) as any
42 }
43 return undefined as any
44}
Note: See TracBrowser for help on using the repository browser.