From 72438d27f7dc174c78842e6bf8933d82fa468f5f Mon Sep 17 00:00:00 2001 From: ellawaal Date: Tue, 8 Sep 2026 16:19:06 +0200 Subject: [PATCH 1/2] lagt til useLocalStorage for senere bruk --- src/hooks/useLocalStorage.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/hooks/useLocalStorage.ts diff --git a/src/hooks/useLocalStorage.ts b/src/hooks/useLocalStorage.ts new file mode 100644 index 0000000..650c88d --- /dev/null +++ b/src/hooks/useLocalStorage.ts @@ -0,0 +1,18 @@ +import { useEffect, useState } from "react" + +function useLocalStorage(key: string, initialValue: T) { + const [value, setValue] = useState(() => { + try { + const stored = localStorage.getItem(key) + return stored ? JSON.parse(stored) : initialValue + } catch { + return initialValue + } + }) + + useEffect(() => { + localStorage.setItem(key, JSON.stringify(value)) + }, [key, value]) + + return [value, setValue] as const +} \ No newline at end of file From 14a5f2c129efa3efc3367d83c45b78b5f20a673f Mon Sep 17 00:00:00 2001 From: ellawaal Date: Thu, 10 Sep 2026 07:41:05 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Lagt=20til=20export=20p=C3=A5=20funksjonsde?= =?UTF-8?q?klarasjonen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useLocalStorage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useLocalStorage.ts b/src/hooks/useLocalStorage.ts index 650c88d..7ab69f2 100644 --- a/src/hooks/useLocalStorage.ts +++ b/src/hooks/useLocalStorage.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from "react" -function useLocalStorage(key: string, initialValue: T) { +export function useLocalStorage(key: string, initialValue: T) { const [value, setValue] = useState(() => { try { const stored = localStorage.getItem(key)