MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / useLocalStorage

Function useLocalStorage

frontend/src/hooks/useLocalStorage.jsx:3–26  ·  view source on GitHub ↗
(key, defaultValue)

Source from the content-addressed store, hash-verified

1import { useEffect, useState } from 'react';
2
3const useLocalStorage = (key, defaultValue) => {
4 const localKey = key;
5
6 const [value, setValue] = useState(() => {
7 try {
8 const item = localStorage.getItem(localKey);
9 return item ? JSON.parse(item) : defaultValue;
10 } catch (error) {
11 console.error(`Error reading key "${localKey}":`, error);
12 }
13
14 return defaultValue;
15 });
16
17 useEffect(() => {
18 try {
19 localStorage.setItem(localKey, JSON.stringify(value));
20 } catch (error) {
21 console.error(`Error saving setting: ${localKey}:`, error);
22 }
23 }, [localKey, value]);
24
25 return [value, setValue];
26};
27
28export default useLocalStorage;

Callers 15

EventFunction · 0.85
SystemEventsFunction · 0.85
M3UTableFunction · 0.85
StreamProfilesFunction · 0.85
OutputProfilesFunction · 0.85
UserAgentsTableFunction · 0.85
VODLogoRowActionsFunction · 0.85
StreamsTableFunction · 0.85
EPGsTableFunction · 0.85
LogoRowActionsFunction · 0.85
LogosTableFunction · 0.85
ChannelsTableFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected