2.0.1 • Published 3 years ago
use-active-heading v2.0.1
use-active-heading
Determine which section a user is reading with IntersectionObservers
Install
npm install --save use-active-heading
Usage
import * as React from "react";
import { useActiveHeading } from "use-active-heading";
const Example = () => {
const activeId = useActiveHeading(["#a", "#b"], {});
return (
<>
<p>ActiveId:{activeId}</p>
<h1 id="a">A</h1>
<h2 id="b" style={{ marginTop: "100vh" }}>
B
</h2>
</>
);
};
License
MIT © sallto
Thanks to create-react-hook for making the npm process understandable.