Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch useLocalStorage setting the right initial value to avoid a hydration error #356

Merged
merged 4 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/esm/useLocalStorage/useLocalStorage.js b/dist/esm/useLocalStorage/useLocalStorage.js
index b0d584d4df29953551dfcf8febac002f89fa7acd..920ae5c52d28af73e3a892bdb935a7805a0f8224 100644
--- a/dist/esm/useLocalStorage/useLocalStorage.js
+++ b/dist/esm/useLocalStorage/useLocalStorage.js
@@ -14,7 +14,7 @@ function useLocalStorage(key, initialValue) {
return initialValue;
}
}, [initialValue, key]);
- const [storedValue, setStoredValue] = useState(readValue);
+ const [storedValue, setStoredValue] = useState(initialValue);
const setValue = useEventCallback(value => {
if (typeof window === 'undefined') {
console.warn(`Tried setting localStorage key “${key}” even though environment is not a client`);
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"devDependencies": {
"husky": "^8.0.1",
"lint-staged": "^13.0.3"
},
"resolutions": {
"usehooks-ts@^2.7.2": "patch:usehooks-ts@npm%3A2.7.2#./.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch"
}
}
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13214,7 +13214,7 @@ __metadata:
languageName: node
linkType: hard

"usehooks-ts@npm:^2.7.2":
"usehooks-ts@npm:2.7.2":
version: 2.7.2
resolution: "usehooks-ts@npm:2.7.2"
peerDependencies:
Expand All @@ -13224,6 +13224,16 @@ __metadata:
languageName: node
linkType: hard

"usehooks-ts@patch:usehooks-ts@npm%3A2.7.2#./.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch::locator=se-2%40workspace%3A.":
version: 2.7.2
resolution: "usehooks-ts@patch:usehooks-ts@npm%3A2.7.2#./.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch::version=2.7.2&hash=68bde7&locator=se-2%40workspace%3A."
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
checksum: 7c79b57c9378e1043156ec1c339e0d6abaaf803e72cb46b61af82dbe2f0f19c29a2b6ede788a5d3969641df509485949c21b181aee5c462105b4605c40433385
languageName: node
linkType: hard

"utf-8-validate@npm:^5.0.2":
version: 5.0.9
resolution: "utf-8-validate@npm:5.0.9"
Expand Down