Skip to content

Commit 5ffb970

Browse files
committed
Add README positioning section and fix Usage snippets
The Usage snippets mounted with `render` from `react-dom`, which React 19 removed, so the first thing a new user copied threw at runtime. They now show the component only, dropping the mount boilerplate. Adds a "When to Use This" section covering when a drop-in router-integrated bar is the better fit and when this package is, with a nav entry alongside the existing sections.
1 parent 0e4147e commit 5ffb970

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88

99
> A React primitive for building slim progress bars.
1010
11-
[Background](#background) | [Usage](#usage) | [Live Examples](#live-examples) | [API](#api) | [Installation](#installation) | [License](#license)
11+
[Background](#background) | [When to Use This](#when-to-use-this) | [Usage](#usage) | [Live Examples](#live-examples) | [API](#api) | [Installation](#installation) | [License](#license)
1212

1313
## Background
1414

1515
This is a React port of [rstacruz](https://github.com/rstacruz)'s [`nprogress`](https://github.com/rstacruz/nprogress) module. It exposes an API that encapsulates the logic of `nprogress` and renders nothing, allowing consumers to implement their own rendering.
1616

17+
## When to Use This
18+
19+
This package is a headless primitive. It renders no markup and ships no CSS, supplying only the pacing state: a `progress` value that trickles towards completion, an `isFinished` flag, and the `animationDuration` to transition with. The bar itself is yours to write.
20+
21+
- Use a drop-in bar such as [`nextjs-toploader`](https://github.com/TheSGJ/nextjs-toploader), [`next-nprogress-bar`](https://github.com/Skyleen77/next-nprogress-bar), or [`nprogress`](https://github.com/rstacruz/nprogress) itself when you want a styled bar wired up to your router with no rendering work.
22+
- Use this package when you render the bar yourself, for example with design-system components or custom containers and spinners, and want only the trickle and completion logic handled for you.
23+
- Use this package when you need several progress bars on one page, each tracking its own state.
24+
1725
## Usage
1826

1927
In the following examples, `Container`, `Bar` and `Spinner` are custom components.
@@ -22,8 +30,6 @@ In the following examples, `Container`, `Bar` and `Spinner` are custom component
2230

2331
```jsx
2432
import { useNProgress } from '@tanem/react-nprogress'
25-
import React from 'react'
26-
import { render } from 'react-dom'
2733

2834
import Bar from './Bar'
2935
import Container from './Container'
@@ -41,31 +47,26 @@ const Progress = ({ isAnimating }) => {
4147
</Container>
4248
)
4349
}
44-
45-
render(<Progress isAnimating />, document.getElementById('root'))
4650
```
4751

4852
**Render Props**
4953

5054
```jsx
5155
import { NProgress } from '@tanem/react-nprogress'
52-
import React from 'react'
53-
import { render } from 'react-dom'
5456

5557
import Bar from './Bar'
5658
import Container from './Container'
5759
import Spinner from './Spinner'
5860

59-
render(
60-
<NProgress isAnimating>
61+
const Progress = ({ isAnimating }) => (
62+
<NProgress isAnimating={isAnimating}>
6163
{({ animationDuration, isFinished, progress }) => (
6264
<Container animationDuration={animationDuration} isFinished={isFinished}>
6365
<Bar animationDuration={animationDuration} progress={progress} />
6466
<Spinner />
6567
</Container>
6668
)}
67-
</NProgress>,
68-
document.getElementById('root')
69+
</NProgress>
6970
)
7071
```
7172

0 commit comments

Comments
 (0)