Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when setting delta: undefined #295

Closed
simonflk opened this issue Feb 25, 2022 · 2 comments · Fixed by #296
Closed

TypeError when setting delta: undefined #295

simonflk opened this issue Feb 25, 2022 · 2 comments · Fixed by #296
Assignees

Comments

@simonflk
Copy link

simonflk commented Feb 25, 2022

Describe the bug

Using useSwipeable() with an explicit delta: undefined, will cause an exception since v6.2.0:

useSwipeable({ onSwiped: console.log, delta: undefined })

Results in this error (when swiping):

TypeError: Cannot read properties of undefined (reading 'up')

Steps or Sandbox to reproduce

See the following example:

https://codesandbox.io/s/react-swipeable-image-carousel-forked-obuesx?file=/src/index.js

I have modified the Carousel component to accept a prop which is passed as delta to useSwipeable

Expected behavior

Either the default delta should be applied, or the handlers should not be attached.

** Device/Browser **

Chrome 98, macOS

Additional context

Error occurs in 6.2.0, but not in earlier versions.

Seems to be a bug introduced in #260 (expecting that delta is either a number or an object)

And also #185 (setting the props like so):

transientProps.current = { ...defaultProps, ...options };

My workaround for now is to rather default delta to {}.

@hartzis
Copy link
Collaborator

hartzis commented Feb 26, 2022

@simonflk Thank you for the detailed issue and example codesandbox, i greatly appreciate it, so helpful to see the issue and try it out.

Thank you for also identifying the culprit. These config values types do call out undefined as a valid type. I'll work on a bug fix for this tonight with a test for undefined for all config values. Something similar was also identified recently, #240 (comment) .

My workaround for now is to rather default delta to {}.

May I suggest defaulting to 0 instead? It's a bit more inline as a default.

useSwipeable({
  delta: customDelta || 0
})

@hartzis
Copy link
Collaborator

hartzis commented Mar 18, 2022

fixed with https://github.com/FormidableLabs/react-swipeable/releases/tag/v6.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants