File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,30 @@ export const MAX_SEARCHES = 5;
77
88type State = { searches : string [ ] ; mounted : boolean } ;
99
10+ function loadFromStorage ( ) : string [ ] {
11+ let saved : string [ ] = [ ] ;
12+ try {
13+ const stored = localStorage . getItem ( STORAGE_KEY ) ;
14+ if ( stored ) saved = JSON . parse ( stored ) as string [ ] ;
15+ } catch {
16+ // ignore malformed storage
17+ }
18+ return saved ;
19+ }
20+
21+ function writeStorage ( searches : string [ ] | null ) : void {
22+ try {
23+ if ( searches === null ) {
24+ localStorage . removeItem ( STORAGE_KEY ) ;
25+ return ;
26+ }
27+
28+ localStorage . setItem ( STORAGE_KEY , JSON . stringify ( searches ) ) ;
29+ } catch {
30+ // ignore storage write failures
31+ }
32+ }
33+
1034export function useRecentSearches ( ) {
1135 // Always start with [] and mounted:false on both server and client so the
1236 // initial render matches (SSR-safe). A single setState in the mount effect
You can’t perform that action at this time.
0 commit comments