MCPcopy Create free account
hub / github.com/FormidableLabs/react-swipeable / useSwipeable

Function useSwipeable

src/index.ts:369–416  ·  view source on GitHub ↗
(options: SwipeableProps)

Source from the content-addressed store, hash-verified

367}
368
369export function useSwipeable(options: SwipeableProps): SwipeableHandlers {
370 const { trackMouse } = options;
371 const transientState = React.useRef({ ...initialState });
372 const transientProps = React.useRef<SwipeablePropsWithDefaultOptions>({
373 ...defaultProps,
374 });
375
376 // track previous rendered props
377 const previousProps = React.useRef<SwipeablePropsWithDefaultOptions>({
378 ...transientProps.current,
379 });
380 previousProps.current = { ...transientProps.current };
381
382 // update current render props & defaults
383 transientProps.current = {
384 ...defaultProps,
385 ...options,
386 };
387 // Force defaults for config properties
388 let defaultKey: keyof ConfigurationOptions;
389 for (defaultKey in defaultProps) {
390 if (transientProps.current[defaultKey] === void 0) {
391 (transientProps.current[defaultKey] as any) = defaultProps[defaultKey];
392 }
393 }
394
395 const [handlers, attachTouch] = React.useMemo(
396 () =>
397 getHandlers(
398 (stateSetter) =>
399 (transientState.current = stateSetter(
400 transientState.current,
401 transientProps.current
402 )),
403 { trackMouse }
404 ),
405 [trackMouse]
406 );
407
408 transientState.current = updateTransientState(
409 transientState.current,
410 transientProps.current,
411 previousProps.current,
412 attachTouch
413 );
414
415 return handlers;
416}

Callers 9

SwipeableUsingHookFunction · 0.90
TestHookComponentFunction · 0.90
SwipeDemoFunction · 0.85
SwipeableHookFunction · 0.85
CarouselFunction · 0.85
CarouselFunction · 0.85
SwipeableHookFunction · 0.85
CarouselFunction · 0.85
CarouselFunction · 0.85

Calls 2

getHandlersFunction · 0.85
updateTransientStateFunction · 0.85

Tested by 2

SwipeableUsingHookFunction · 0.72
TestHookComponentFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…