mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 01:11:13 -05:00
Improve handling of recent searches to prevent errors
Add error handling and validation for parsing recent searches from localStorage in src/hooks/useSearch.tsx. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 8e00d8b1-e8de-4f48-99ca-dbba7279e1a6 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -46,9 +46,17 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
|
||||
// Load recent searches from localStorage
|
||||
useEffect(() => {
|
||||
const stored = localStorage.getItem('thrillwiki_recent_searches');
|
||||
if (stored) {
|
||||
setRecentSearches(JSON.parse(stored));
|
||||
try {
|
||||
const stored = localStorage.getItem('thrillwiki_recent_searches');
|
||||
if (stored) {
|
||||
const parsed = JSON.parse(stored);
|
||||
if (Array.isArray(parsed)) {
|
||||
setRecentSearches(parsed);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to parse recent searches from localStorage:', error);
|
||||
localStorage.removeItem('thrillwiki_recent_searches');
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user