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

Function updateTransientState

src/index.ts:325–367  ·  view source on GitHub ↗
(
  state: SwipeableState,
  props: SwipeablePropsWithDefaultOptions,
  previousProps: SwipeablePropsWithDefaultOptions,
  attachTouch: AttachTouch
)

Source from the content-addressed store, hash-verified

323}
324
325function updateTransientState(
326 state: SwipeableState,
327 props: SwipeablePropsWithDefaultOptions,
328 previousProps: SwipeablePropsWithDefaultOptions,
329 attachTouch: AttachTouch
330) {
331 // if trackTouch is off or there is no el, then remove handlers if necessary and exit
332 if (!props.trackTouch || !state.el) {
333 if (state.cleanUpTouch) {
334 state.cleanUpTouch();
335 }
336
337 return {
338 ...state,
339 cleanUpTouch: undefined,
340 };
341 }
342
343 // trackTouch is on, so if there are no handlers attached, attach them and exit
344 if (!state.cleanUpTouch) {
345 return {
346 ...state,
347 cleanUpTouch: attachTouch(state.el, props),
348 };
349 }
350
351 // trackTouch is on and handlers are already attached, so if preventScrollOnSwipe changes value,
352 // remove and reattach handlers (this is required to update the passive option when attaching
353 // the handlers)
354 if (
355 props.preventScrollOnSwipe !== previousProps.preventScrollOnSwipe ||
356 props.touchEventOptions.passive !== previousProps.touchEventOptions.passive
357 ) {
358 state.cleanUpTouch();
359
360 return {
361 ...state,
362 cleanUpTouch: attachTouch(state.el, props),
363 };
364 }
365
366 return state;
367}
368
369export function useSwipeable(options: SwipeableProps): SwipeableHandlers {
370 const { trackMouse } = options;

Callers 1

useSwipeableFunction · 0.85

Calls 1

attachTouchFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…