{"id":20638898,"url":"https://github.com/merri/react-tap-or-click","last_synced_at":"2026-03-05T07:37:34.489Z","repository":{"id":57346181,"uuid":"46100269","full_name":"Merri/react-tap-or-click","owner":"Merri","description":"[DEPRECATED: mobile browsers in 2017 have instant clicks] Minimal and easy to use mobile click solution for React","archived":false,"fork":false,"pushed_at":"2017-04-28T11:30:21.000Z","size":10,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T22:43:58.819Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Merri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-13T04:37:23.000Z","updated_at":"2023-08-23T09:52:30.000Z","dependencies_parsed_at":"2022-09-17T23:12:31.400Z","dependency_job_id":null,"html_url":"https://github.com/Merri/react-tap-or-click","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Merri/react-tap-or-click","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Merri%2Freact-tap-or-click","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Merri%2Freact-tap-or-click/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Merri%2Freact-tap-or-click/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Merri%2Freact-tap-or-click/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Merri","download_url":"https://codeload.github.com/Merri/react-tap-or-click/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Merri%2Freact-tap-or-click/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259470941,"owners_count":22862997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T15:20:33.771Z","updated_at":"2026-03-05T07:37:34.418Z","avatar_url":"https://github.com/Merri.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-tap-or-click\n\nYou know. That 300ms tap delay. This problem has been around for quite a while and there are various solutions to the\nproblem such as [fastclick](https://github.com/ftlabs/fastclick) and\n[react-tap-event-plugin](https://github.com/zilverline/react-tap-event-plugin).\n\n`tapOrClick` is the simplest solution to the problem: it triggers a given callback when `onTouchEnd` is\ntriggered, or `onClick` if there are no touch events. This probably covers all use cases where you simply want an\nimmediate click.\n\nIn addition `tapOrClick` hides the complexity of the issue so you don't need to think about what kind of hellish\nwizardry needs to be done just to get an immediate click! `tapOrClick` is scrolling aware and does not trigger clicks\nwhen scrolling. Also, [ghost clicks](http://ariatemplates.com/blog/2014/05/ghost-clicks-in-mobile-browsers/) are busted.\n\nThis utility has been designed to be easy to use with React, but you can use it elsewhere; it just might not be as\nconvenient as with React. If you wish to have easier support for your use case then please open a new issue and we'll\nsee what can be done!\n\n## How?\n\n`react-tap-or-click` is only usable as npm module. Thus: `npm i react-tap-or-click`\n\n### Babel and JSX\n\n```jsx\nimport React from 'react'\nimport tapOrClick from 'react-tap-or-click'\n\nconst YourComponent = React.createClass({\n    handleClick(event) {\n        alert(event.type)\n    },\n\n    render() {\n        return \u003cdiv {...tapOrClick(this.handleClick)}\u003e\n            My Component\n        \u003c/div\u003e  \n    }\n})\n\nexport default YourComponent\n```\n\n### ES5\n\n```js\n'use strict'\nvar React = require('react')\nvar tapOrClick = require('react-tap-or-click')\n\nvar YourComponent = React.createClass({\n    handleClick: function(event) {\n        alert(event.type)\n    },\n\n    render: function() {\n        var props = {\n            style: {\n                backgroundColor: '#EEE'\n            }\n        }\n\n        // you can pass props as second argument to extend that props object\n        return React.DOM.div(\n            tapOrClick(this.handleClick, props),\n            'My Component'\n        )\n    }\n})\n\nmodule.exports = YourComponent\n```\n\n## Why?\n\n1. Because about 4 kB of non-minified code (2.3 kB minified) should be enough to solve this problem.\n2. `fastclick` causes nasty side effects and hard-to-understand bugs when used with React.\n3. `react-tap-event-plugin` contains a lot of code, may require you to build your own minified React bundle and you\nhave to define two handlers for the same thing (`onTapEvent` and `onClick`).\n\n## Notes\n\n- `react-tap-or-click` always respects `event.preventDefault()`.\n- Any existing `onTouchStart`, `onTouchEnd` or `onClick` will be overwritten.\n- Up to 10000 callbacks are cached at once. Cache is flushed if going over limit. You may have a design flaw if you hit\nthis size on a regular page. This is warned about with a normal `console.log`.\n- The code could be more compact if it had less abstractions; the current code ought to be readable enough so you can\nunderstand it, too!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmerri%2Freact-tap-or-click","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmerri%2Freact-tap-or-click","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmerri%2Freact-tap-or-click/lists"}