npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mr-scrollspy

v0.0.5

Published

React에서 ScrollSpy 기능을 간단하게 사용할 수 있도록 만든 **React Hook 라이브러리**입니다.

Readme

🥸 mr-scrollspy

React에서 ScrollSpy 기능을 간단하게 사용할 수 있도록 만든 React Hook 라이브러리입니다.

IntersectionObserver API를 사용하여 각 섹션이 viewport에 진입하는 시점을 감지합니다. 또한, 여러 섹션을 감지하는 경우 불필요한 Observer 생성을 방지하기 위해 Observer Pooling 구조를 적용하여 성능을 최적화했습니다.

✅ 주요 기능

  • ⚡ IntersectionObserver 기반 ScrollSpy
  • 🧠 Observer Pooling으로 불필요한 Observer 생성 방지
  • 🪶 Lightweight (~1kb bundle)
  • ⚛️ React 18 / 19 지원
  • 🧾 TypeScript 지원
  • 📦 ESM / CJS 번들 제공

✅ 설치

npm install mr-scrollspy
yarn add mr-scrollspy

✅ 사용 방법

1️⃣ 섹션 ref 생성

ScrollSpy로 감지할 섹션의 ref를 생성합니다.

import { useRef } from "react";

const sectionRefs = {
  visual: useRef<HTMLDivElement>(null),
  notice: useRef<HTMLDivElement>(null),
  ai: useRef<HTMLDivElement>(null),
};

2️⃣ useScrollSpy 사용

현재 화면에 보이는 섹션의 id가 activeSection 값으로 반환됩니다.

import { useScrollSpy } from "mr-scrollspy";

const activeSection = useScrollSpy({
  sectionRefs,
  offset: 100,
});

3️⃣ 메뉴 활성화 처리

<ul>
  <li className={activeSection === "visual" ? "active" : ""}>
    Visual
  </li>

  <li className={activeSection === "notice" ? "active" : ""}>
    Notice
  </li>

  <li className={activeSection === "ai" ? "active" : ""}>
    AI
  </li>
</ul>

✅ 전체 예제

import { useRef } from "react";
import { useScrollSpy } from "mr-scrollspy";

function Page() {
  const sectionRefs = {
    visual: useRef<HTMLDivElement>(null),
    notice: useRef<HTMLDivElement>(null),
    ai: useRef<HTMLDivElement>(null),
  };

  const activeId = useScrollSpy({
    sectionRefs,
    offset: 120,
  });

  return (
    <>
      <nav>
        <button className={activeId === "visual" ? "active" : ""}>
          Visual
        </button>

        <button className={activeId === "notice" ? "active" : ""}>
          Notice
        </button>

        <button className={activeId === "ai" ? "active" : ""}>
          AI
        </button>
      </nav>

      <section ref={sectionRefs.visual}>Visual Section</section>
      <section ref={sectionRefs.notice}>Notice Section</section>
      <section ref={sectionRefs.ai}>AI Section</section>
    </>
  );
}

✅ useScrollSpy(options)

  • sectionRefs<Record<string, RefObject>> : 감지할 섹션 ref 객체
  • offset : 스크롤 오프셋(고정 헤더 높이)

✅ 사용 사례

  • 랜딩 페이지 섹션 네비게이션
  • 블로그 목차
  • 문서 페이지 앵커 네비게이션
  • 스크롤 기반 메뉴 활성화 UI