{"id":20705716,"url":"https://github.com/zamarawka/use-drags","last_synced_at":"2026-04-10T01:45:01.828Z","repository":{"id":36039808,"uuid":"220877749","full_name":"zamarawka/use-drags","owner":"zamarawka","description":"Useful way to handle drag gestures. Covers whole drag and drop lifecycle.","archived":false,"fork":false,"pushed_at":"2023-01-05T00:47:10.000Z","size":2199,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-07T16:41:37.573Z","etag":null,"topics":["drag-and-drop","javascript","npm-package","react","reacthook"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/zamarawka.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":"2019-11-11T01:35:13.000Z","updated_at":"2023-01-31T17:41:56.000Z","dependencies_parsed_at":"2023-01-16T12:14:36.473Z","dependency_job_id":null,"html_url":"https://github.com/zamarawka/use-drags","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zamarawka%2Fuse-drags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zamarawka%2Fuse-drags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zamarawka%2Fuse-drags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zamarawka%2Fuse-drags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zamarawka","download_url":"https://codeload.github.com/zamarawka/use-drags/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242973988,"owners_count":20215251,"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":["drag-and-drop","javascript","npm-package","react","reacthook"],"created_at":"2024-11-17T01:19:19.311Z","updated_at":"2025-12-25T01:03:04.088Z","avatar_url":"https://github.com/zamarawka.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Ci Status](https://github.com/zamarawka/use-drags/workflows/CI/badge.svg)](https://github.com/zamarawka/use-drags/actions)\n[![Npm version](https://img.shields.io/npm/v/use-drags.svg?style=flat\u0026logo=npm)](https://www.npmjs.com/package/use-drags)\n[![React version](https://img.shields.io/npm/dependency-version/use-drags/peer/react.svg?style=flat\u0026logo=react)](https://reactjs.org/)\n\n# use-drags\n\nHandle drag events without overhead by only 1 callback. React hook for manage drag and drop lifecycle without extra business or view logic.\nUseful as base for custom UI components with draggable elements.\n\n[Demo](https://zamarawka.github.io/use-drags/)\n\nPackage includes its TypeScript Definitions\n\n# Install\n\n```sh\nnpm install use-drags\n```\n\n# Usage\n\n```jsx\nimport React, { useRef, useState } = 'react';\nimport useDrags from 'use-drags';\n\nfunction DraggableBlock() {\n  const ref = useRef(null);\n  const [position, setPosition] = useState(null);\n\n  useDrags(ref, ({\n    el,\n    first,\n    last,\n    deltaX,\n    deltaY,\n    offsetX,\n    offsetY,\n    clientX,\n    clientY,\n  }) =\u003e {\n    if (first) {\n      el.style.opacity = 0.5;\n    }\n\n    if (last) {\n      el.style.opacity = null;\n      el.style.transform = null;\n      setPosition(null);\n\n      return;\n    }\n\n    setPosition({ clientX, clientY });\n\n    el.style.transform = `translate3d(${offsetX}px, ${offsetY}px, 0)`;\n  });\n\n  return (\n    \u003cdiv ref={ref}\u003e\n      \u003cspan\u003eDrag me!\u003c/span\u003e\n      {position !== null \u0026\u0026\n        \u003cspan\u003eX: {position.clientX }, Y: {position.clientY}\u003c/span\u003e\n      }\n    \u003c/div\u003e\n  );\n}\n```\n\n# Development\n\n```sh\nnpm run lint # linting\nnpm run test # testing\n```\n\nActive maintenance with care and ❤️.\n\nFeel free to send a PR.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzamarawka%2Fuse-drags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzamarawka%2Fuse-drags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzamarawka%2Fuse-drags/lists"}