Skip to content

Commit a3326b6

Browse files
Merge pull request #131 from uidotdev/patch-1
Add an extra note to explain the typeof window !== "undefined" checks.
2 parents af27cc3 + a88cf0b commit a3326b6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/pages/useLocalStorage.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Sync state to local storage so that it persists through a page refresh.
1515
Usage is similar to useState except we pass in a local storage key so that we can
1616
default to that value on page load instead of the specified initial value.
1717

18+
Since the local storage API isn't available in server-rendering environments,
19+
we check that `typeof window !== "undefined"` to make SSR and SSG work properly.
20+
1821
```jsx
1922
import { useState } from "react";
2023

0 commit comments

Comments
 (0)