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",
"version": "5.7.16",
"version": "5.7.17",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "pashto-inflector",
"version": "5.7.16",
"version": "5.7.17",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {

View File

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

View File

@ -1,6 +1,6 @@
{
"name": "@lingdocs/ps-react",
"version": "5.7.16",
"version": "5.7.17",
"description": "Pashto inflector library module with React components",
"main": "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>>,
] {
const [value, setValue] = useState<T>(() => {
const v = window.localStorage.getItem(key);
const v = typeof window === "undefined"
? null
: window.localStorage.getItem(key);
// nothing saved
if (v === null) {
if (typeof defaultValue === "function") {
@ -39,7 +41,9 @@ export default function useStickyState<T extends SaveableData>(defaultValue: T |
});
useEffect(() => {
window.localStorage.setItem(key, JSON.stringify(value));
if (typeof window !== undefined) {
window.localStorage.setItem(key, JSON.stringify(value));
}
}, [key, value]);
return [value, setValue];

View File

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