patch up for ssr compatiblity

This commit is contained in:
adueck 2023-02-17 20:56:26 +05:00
parent fc8142b56e
commit 540b9d91dd
5 changed files with 11 additions and 7 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.7.16", "version": "5.7.17",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.7.16", "version": "5.7.17",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.7.16", "version": "5.7.17",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "5.7.16", "version": "5.7.17",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -15,7 +15,9 @@ export default function useStickyState<T extends SaveableData>(defaultValue: T |
setValue: React.Dispatch<React.SetStateAction<T>>, setValue: React.Dispatch<React.SetStateAction<T>>,
] { ] {
const [value, setValue] = useState<T>(() => { const [value, setValue] = useState<T>(() => {
const v = window.localStorage.getItem(key); const v = typeof window === "undefined"
? null
: window.localStorage.getItem(key);
// nothing saved // nothing saved
if (v === null) { if (v === null) {
if (typeof defaultValue === "function") { if (typeof defaultValue === "function") {
@ -39,7 +41,9 @@ export default function useStickyState<T extends SaveableData>(defaultValue: T |
}); });
useEffect(() => { useEffect(() => {
if (typeof window !== undefined) {
window.localStorage.setItem(key, JSON.stringify(value)); window.localStorage.setItem(key, JSON.stringify(value));
}
}, [key, value]); }, [key, value]);
return [value, setValue]; return [value, setValue];

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "5.7.16", "version": "5.7.17",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",