Skip to content

Commit

Permalink
new readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
underfisk committed Aug 6, 2022
1 parent 7c4e0a4 commit 841a588
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# use-simply-scroll-spy
# use-simple-scroll-spy

Tiny scroll spy react hook that just needs the element ids

## Installation

```
pnpm i use-simply-scroll-spy
```

```
yarn add use-simply-scroll-spy
```

```
npm i use-simply-scroll-spy
```

## Usage

```typescript
const sectionIds = ["section-1", "section-2"];
const MyComponent: React.FC = () => {
const activeIndex = useSimpleScrollSpy(sectionIds);
return (
<>
<div id="section-1">My content </div>
<div id="section-2">My content </div>
</>
);
};
```

The code above is a very simply way of using this hook but the general idea is to track based on the URL hash. If you hit the page with `#section-2` as the default section, the `activeIndex` will be set propertly.

My personal motivation for this project was the need in a very framework-agnostic in order to create an header with the active section

0 comments on commit 841a588

Please sign in to comment.