@fremtind/jkl-react-hooks
Advanced tools
Comparing version
@@ -34,7 +34,10 @@ "use strict"; | ||
const updateState = (0, import_react.useCallback)( | ||
(newValue) => { | ||
setState(newValue); | ||
if (typeof window !== "undefined" && localStorage) { | ||
localStorage.setItem(key, JSON.stringify(newValue)); | ||
} | ||
(setStateAction) => { | ||
setState((previousValue) => { | ||
const newValue = typeof setStateAction === "function" ? setStateAction(previousValue) : setStateAction; | ||
if (typeof window !== "undefined" && localStorage) { | ||
localStorage.setItem(key, JSON.stringify(newValue)); | ||
} | ||
return newValue; | ||
}); | ||
}, | ||
@@ -41,0 +44,0 @@ [key] |
@@ -11,7 +11,10 @@ import { useCallback, useState } from "react"; | ||
const updateState = useCallback( | ||
(newValue) => { | ||
setState(newValue); | ||
if (typeof window !== "undefined" && localStorage) { | ||
localStorage.setItem(key, JSON.stringify(newValue)); | ||
} | ||
(setStateAction) => { | ||
setState((previousValue) => { | ||
const newValue = typeof setStateAction === "function" ? setStateAction(previousValue) : setStateAction; | ||
if (typeof window !== "undefined" && localStorage) { | ||
localStorage.setItem(key, JSON.stringify(newValue)); | ||
} | ||
return newValue; | ||
}); | ||
}, | ||
@@ -18,0 +21,0 @@ [key] |
@@ -1,1 +0,1 @@ | ||
export declare const useLocalStorage: <T>(key: string, defaultValue: T) => [T, (newValue: T) => void]; | ||
export declare const useLocalStorage: <T>(key: string, defaultValue: T) => [T, React.Dispatch<React.SetStateAction<T>>]; |
{ | ||
"name": "@fremtind/jkl-react-hooks", | ||
"version": "12.2.20", | ||
"version": "12.3.0", | ||
"publishConfig": { | ||
@@ -57,3 +57,3 @@ "access": "public" | ||
}, | ||
"gitHead": "7f500c4616902d7be29ebcb80abb1cedc96b14f3" | ||
"gitHead": "75278c5ff95c8ed3c51bae7611ef7586a20d558f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
311779
0.39%3625
0.17%