Skip to content

Commit ee29df6

Browse files
docs(hooks/use-revalidator): update code example (#9992)
Co-authored-by: Matt Brophy <[email protected]>
1 parent 2be8bc7 commit ee29df6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/hooks/use-revalidator.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ Initiates a revalidation.
3939

4040
```tsx
4141
function useLivePageData() {
42-
const revalidator = useRevalidator();
43-
const interval = useInterval(5000);
42+
const revalidator = useRevalidator()
4443

45-
useEffect(() => {
46-
if (revalidator.state === "idle") {
47-
revalidator.revalidate();
44+
useInterval(() => {
45+
if (revalidator.state === 'idle') {
46+
revalidator.revalidate()
4847
}
49-
}, [interval, revalidator]);
48+
}, 5000)
5049
}
5150
```
5251

52+
See [here](https://overreacted.io/making-setinterval-declarative-with-react-hooks/) for a sample `useInterval` implementation.
53+
5354
## Notes
5455

5556
While you can render multiple occurrences of `useRevalidator` at the same time, underneath it is a singleton. This means when one `revalidator.revalidate()` is called, all instances go into the `"loading"` state together (or rather, they all update to report the singleton state).

0 commit comments

Comments
 (0)