-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Make hooks SSR-safe and type-safe (see comment) Pass an optional `{ initializeWithValue?: boolean }` object to make them SSR-safe - useElementSize - useMediaQuery - useScreen - useSessionStorage - useLocalStorage - useWindowSize - useReadLocalStorage - useDarkMode - useTernaryDarkMode * 🔖 Add changeset * 📝 Update the documentation
- Loading branch information
Showing
22 changed files
with
352 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'usehooks-ts': minor | ||
--- | ||
|
||
Pass an optional `{ initializeWithValue?: boolean }` object to make some hooks SSR-safe (useLocalStorage, useReadLocalStorage, useSessionStorage, useDarkMode, useTernaryDarkMode, useMediaQuery, useScreen, useWindowSize, useElementSize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"usehooks-ts": minor | ||
--- | ||
|
||
Drop Set & Map support in use\*Storage hooks (it was a done before in deserializer, but forgotten in serializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
This hook helps you to dynamically recover the width and the height of an HTML element. | ||
Dimensions are updated on load, on mount/un-mount, when resizing the window and when the ref changes. | ||
|
||
**Note**: If you use this hook in an SSR context, set the `initializeWithValue` option to `false`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 6 additions & 8 deletions
14
packages/usehooks-ts/src/useLocalStorage/useLocalStorage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
Persist the state with local storage so that it remains after a page refresh. This can be useful for a dark theme. | ||
Persist the state with [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) so that it remains after a page refresh. This can be useful for a dark theme. | ||
This hook is used in the same way as useState except that you must pass the storage key in the 1st parameter. | ||
If the window object is not present (as in SSR), `useLocalStorage()` will return the default value. | ||
|
||
You can also pass an optional third parameter to use a custom serializer/deserializer. | ||
|
||
**Side notes:** | ||
**Note**: If you use this hook in an SSR context, set the `initializeWithValue` option to `false`. | ||
|
||
- If you really want to create a dark theme switch, see [useDarkMode()](/react-hook/use-dark-mode). | ||
- If you just want read value from local storage, see [useReadLocalStorage()](/react-hook/use-read-local-storage). | ||
### Related hooks | ||
|
||
Related hooks: | ||
|
||
- [`useSessionStorage()`](/react-hook/use-session-storage) | ||
- [`useDarkMode()`](/react-hook/use-dark-mode): Helps create a dark theme switch, built on top of `useLocalStorage()`. | ||
- [`useReadLocalStorage()`](/react-hook/use-read-local-storage): Read values from local storage. | ||
- [`useSessionStorage()`](/react-hook/use-session-storage): Its implementation is almost the same of `useLocalStorage()`, but on [session storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.