React Easy Swipe is a JavaScript library providing a simple component for handling touch swipe gestures within React applications. Currently stable at version 0.0.23, it offers straightforward integration for detecting common swipe directions (up, down, left, right) as well as general swipe start, move, and end events. The library differentiates itself by its minimal API and direct focus on touch interactions, with an option to enable mouse events for development. It includes features to prevent page scrolling during a swipe and to set a pixel tolerance for accidental swipes, making it suitable for mobile-first user interfaces. With its last publish date three years ago, releases appear to follow a 'when needed' cadence, characteristic of mature, focused utility libraries.
npm install react-easy-swipeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate the `Swipe` component, define basic swipe event handlers (`onSwipeStart`, `onSwipeMove`, `onSwipeEnd`), and enable `allowMouseEvents` for testing. It also highlights the required `tolerance` prop.
Return `true` from the `onSwipeMove` handler to prevent the default scroll behavior: `onSwipeMove(position, event) { /* ... */ return true; }`.Pass `allowMouseEvents={true}` to the `Swipe` component to enable mouse interaction for testing on desktop environments.Always ensure the `tolerance` prop is provided with a numeric value, e.g., `<Swipe tolerance={10} ...>`.Use your browser's developer tools to enable touch emulation or deploy your application to a mobile device for real-world testing.
Add the `tolerance` prop with a number value, e.g., `<Swipe tolerance={10} ...>`.Use `import Swipe from 'react-easy-swipe';` instead of named imports like `import { Swipe } from 'react-easy-swipe';` or CommonJS `require` for ESM environments.Ensure `position` is defined before accessing its properties within the `onSwipeMove` handler, or add defensive checks if `position` can sometimes be `null` or `undefined`.