Commit 6aa5c2f dschlabach
committed
1 parent 49a2a07 commit 6aa5c2f Copy full SHA for 6aa5c2f
File tree 1 file changed +8
-3
lines changed
playground/nextjs-app-router/lib
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ type StorageConfig<T> = {
32
32
serializer ?: ( value : T ) => string ;
33
33
} ;
34
34
35
+ const OCK_NAMESPACE_PREFIX = 'ock-' ;
36
+
35
37
/**
36
38
* Custom hook to manage state with localStorage
37
39
* Also syncs to URL params on first load
@@ -63,7 +65,7 @@ export function useStateWithStorage<T>({
63
65
}
64
66
65
67
try {
66
- const stored = window . localStorage . getItem ( key ) ;
68
+ const stored = window . localStorage . getItem ( OCK_NAMESPACE_PREFIX + key ) ;
67
69
if ( stored ) {
68
70
setState ( parser ( stored ) as ReturnType ) ;
69
71
}
@@ -81,9 +83,12 @@ export function useStateWithStorage<T>({
81
83
82
84
try {
83
85
if ( state !== undefined ) {
84
- window . localStorage . setItem ( key , serializer ( state ) ) ;
86
+ window . localStorage . setItem (
87
+ OCK_NAMESPACE_PREFIX + key ,
88
+ serializer ( state ) ,
89
+ ) ;
85
90
} else {
86
- window . localStorage . removeItem ( key ) ;
91
+ window . localStorage . removeItem ( OCK_NAMESPACE_PREFIX + key ) ;
87
92
}
88
93
} catch ( e ) {
89
94
console . warn ( `Error writing to localStorage for ${ key } :` , e ) ;
You can’t perform that action at this time.
0 commit comments