Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-swipeable

Package Overview
Dependencies
Maintainers
25
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-swipeable

React Swipe event handler hook

  • 7.0.0-alpha.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
488K
increased by0.16%
Maintainers
25
Weekly downloads
 
Created

What is react-swipeable?

The react-swipeable package is a React component that provides easy-to-use swipe event handlers for touch devices. It allows developers to add swipe functionality to their React components, making it ideal for creating touch-friendly user interfaces.

What are react-swipeable's main functionalities?

Basic Swipe Detection

This code demonstrates how to use the react-swipeable package to detect basic swipe events. The `useSwipeable` hook is used to create swipe handlers, which are then applied to a div element. When a swipe is detected, a message is logged to the console.

import React from 'react';
import { useSwipeable } from 'react-swipeable';

const SwipeComponent = () => {
  const handlers = useSwipeable({
    onSwiped: (eventData) => console.log('User Swiped!', eventData)
  });

  return (
    <div {...handlers} style={{ width: '100%', height: '100px', background: 'lightgray' }}>
      Swipe here
    </div>
  );
};

export default SwipeComponent;

Swipe Direction Detection

This code demonstrates how to detect the direction of a swipe using the react-swipeable package. The `useSwipeable` hook is configured with handlers for each swipe direction (left, right, up, down), and logs a message to the console when a swipe in that direction is detected.

import React from 'react';
import { useSwipeable } from 'react-swipeable';

const SwipeDirectionComponent = () => {
  const handlers = useSwipeable({
    onSwipedLeft: () => console.log('Swiped Left!'),
    onSwipedRight: () => console.log('Swiped Right!'),
    onSwipedUp: () => console.log('Swiped Up!'),
    onSwipedDown: () => console.log('Swiped Down!')
  });

  return (
    <div {...handlers} style={{ width: '100%', height: '100px', background: 'lightblue' }}>
      Swipe in any direction
    </div>
  );
};

export default SwipeDirectionComponent;

Swipe Threshold Configuration

This code demonstrates how to configure a swipe threshold using the react-swipeable package. The `useSwipeable` hook is configured with a `delta` value, which sets the minimum distance (in pixels) that a swipe must cover to be detected.

import React from 'react';
import { useSwipeable } from 'react-swipeable';

const SwipeThresholdComponent = () => {
  const handlers = useSwipeable({
    onSwiped: (eventData) => console.log('User Swiped!', eventData),
    delta: 50 // Minimum distance (in pixels) for a swipe to be detected
  });

  return (
    <div {...handlers} style={{ width: '100%', height: '100px', background: 'lightgreen' }}>
      Swipe with a minimum threshold
    </div>
  );
};

export default SwipeThresholdComponent;

Other packages similar to react-swipeable

Keywords

FAQs

Package last updated on 15 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc