{"id":26045844,"url":"https://github.com/purii/react-use-scrollspy","last_synced_at":"2025-04-12T14:57:03.988Z","repository":{"id":33398463,"uuid":"158081932","full_name":"Purii/react-use-scrollspy","owner":"Purii","description":"Flexible React Hook to automatically update navigation based on scroll position ","archived":false,"fork":false,"pushed_at":"2024-08-15T17:45:17.000Z","size":3479,"stargazers_count":319,"open_issues_count":16,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-05T00:03:21.827Z","etag":null,"topics":["hooks","hooks-api-react","javascript","react","reactjs","scrollspy"],"latest_commit_sha":null,"homepage":"https://purii.github.io/react-use-scrollspy/","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/Purii.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Purii","patreon":"purii"}},"created_at":"2018-11-18T12:33:58.000Z","updated_at":"2024-10-09T12:44:51.000Z","dependencies_parsed_at":"2024-10-28T21:49:32.373Z","dependency_job_id":null,"html_url":"https://github.com/Purii/react-use-scrollspy","commit_stats":{"total_commits":127,"total_committers":6,"mean_commits":"21.166666666666668","dds":0.6456692913385826,"last_synced_commit":"be27ac60195ac00ee0c01cc0828c0bcc4127f334"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Purii%2Freact-use-scrollspy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Purii%2Freact-use-scrollspy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Purii%2Freact-use-scrollspy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Purii%2Freact-use-scrollspy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Purii","download_url":"https://codeload.github.com/Purii/react-use-scrollspy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586248,"owners_count":21128997,"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":["hooks","hooks-api-react","javascript","react","reactjs","scrollspy"],"created_at":"2025-03-07T20:49:41.699Z","updated_at":"2025-04-12T14:57:03.965Z","avatar_url":"https://github.com/Purii.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Purii","https://patreon.com/purii","https://www.patreon.com/purii"],"categories":[],"sub_categories":[],"readme":"# react-use-scrollspy\n\n[![Build Status](https://travis-ci.org/Purii/react-use-scrollspy.svg?branch=master)](https://travis-ci.org/Purii/react-use-scrollspy)\n[![npm version](http://img.shields.io/npm/v/react-use-scrollspy.svg?style=flat)](https://www.npmjs.com/package/react-use-scrollspy)\n[![npm](https://img.shields.io/npm/dm/react-use-scrollspy.svg)](https://www.npmjs.com/package/react-use-scrollspy)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Purii/react-use-scrollspy/master/LICENSE)\n[![Donate](https://img.shields.io/badge/Donate-Patreon-green.svg)](https://www.patreon.com/purii)\n\n![Example](example.gif)\n\n## Installation\n\n`react-use-scrollspy` is a React `Hook` which requires React **16.8.0 or later.**\n\n```sh\n// yarn\nyarn add react-use-scrollspy\n// or npm\nnpm i react-use-scrollspy --S\n```\n\n## Usage\n\n```javascript\nimport useScrollSpy from 'react-use-scrollspy';\n...\nconst activeSection = useScrollSpy({\n  sectionElementRefs: [], // Array of References to DOM elements\n});\n```\n\n| Parameter          | Default  |  Type   | Description                                                 |\n| :----------------- | :------: | :-----: | ----------------------------------------------------------- |\n| defaultValue       |   `0`    |  `int`  | Default value that is returned (optional)                   |\n| offsetPx           |   `0`    |  `int`  | Set offset (optional)                                       |\n| sectionElementRefs |   `[]`   | `[Ref]` | Array of Refs to observe (e.g. via React `refs`)            |\n| scrollingElement   | `window` |  `Ref`  | Target of the scrolling (e.g. via React `refs`)) (optional) |\n\n### with Refs\n\nUse React `refs` for section elements like in the [provided example](/example).\n\n```javascript\nimport React, { useRef } from 'react';\nimport useScrollSpy from 'react-use-scrollspy';\n\nconst App = () =\u003e {\n\n  const sectionRefs = [\n    useRef(null),\n    useRef(null),\n    useRef(null),\n  ];\n\n  const activeSection = useScrollSpy({\n    sectionElementRefs: sectionRefs,\n    offsetPx: -80,\n  });\n\n  return (\n    \u003cnav className=\"App-navigation\"\u003e\n      \u003cspan className={activeSection === 0 ? \"App-navigation-item App-navigation-item--active\" : \"App-navigation-item\"}\u003eSection 1\u003c/span\u003e\n      \u003cspan className={activeSection === 1 ? \"App-navigation-item App-navigation-item--active\" : \"App-navigation-item\"}\u003eSection 2\u003c/span\u003e\n      \u003cspan className={activeSection === 2 ? \"App-navigation-item App-navigation-item--active\" : \"App-navigation-item\"}\u003eSection 3\u003c/span\u003e\n    \u003c/nav\u003e\n\n    \u003csection className=\"App-section\" ref={sectionRefs[0]}\u003e\n      \u003ch1\u003eSection 1\u003c/h1\u003e\n    \u003c/section\u003e\n    \u003csection className=\"App-section\" ref={sectionRefs[1]}\u003e\n      \u003ch1\u003eSection 2\u003c/h1\u003e\n    \u003c/section\u003e\n    \u003csection className=\"App-section\" ref={sectionRefs[2]}\u003e\n      \u003ch1\u003eSection 3\u003c/h1\u003e\n    \u003c/section\u003e\n  )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurii%2Freact-use-scrollspy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurii%2Freact-use-scrollspy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurii%2Freact-use-scrollspy/lists"}