Git Product home page Git Product logo

react-point's Introduction

react-point Travis npm package

react-point gives you fast touch events for your React applications.

A <PointTarget> normalizes click and click-like touch events (not swipes or drags) into a "point" event. This helps you avoid the 300ms delay for click events on touch interfaces like iOS.

Installation

Using yarn:

$ yarn add react-point

Then, use as you would anything else:

// using ES6 modules
import PointTarget from 'react-point'

// using CommonJS modules
var PointTarget = require('react-point')

The UMD build is also available on unpkg:

<script src="https://unpkg.com/react-point/umd/react-point.min.js"></script>

You can find the library on window.ReactPoint.

Usage

Just render a <PointTarget> component and give it an onPoint function to call whenever the user clicks or taps the element.

import React from 'react'
import PointTarget from 'react-point'

class App extends React.Component {
  handlePoint = () => {
    alert('I was clicked or tapped!')
  }

  render() {
    return (
      <PointTarget onPoint={this.handlePoint}/>
    )
  }
}

By default, a <PointTarget> renders a <button> for accessibility. However, you can use the children prop to make it render something else. For example, to render a <div>:

import React from 'react'
import PointTarget from 'react-point'

class App extends React.Component {
  handlePoint = () => {
    alert('I was clicked or tapped!')
  }

  render() {
    return (
      <PointTarget onPoint={this.handlePoint}>
        <div>Click or tap here</div>
      </PointTarget>
    )
  }
}

Note: The onClick, onTouchStart, onTouchMove, onTouchEnd, and onTouchCancel props will be overwritten because <PointTarget> needs them to do its thing).

About

react-point is developed and maintained by React Training. If you're interested in learning more about what React can do for your company, please get in touch!

react-point's People

Contributors

greenkeeperio-bot avatar mjackson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.