mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 20:35:24 +00:00
24 lines
No EOL
565 B
TypeScript
24 lines
No EOL
565 B
TypeScript
'use client';
|
|
|
|
import { useMemo } from "react";
|
|
import { useLocalStorage } from "usehooks-ts";
|
|
|
|
type Search = {
|
|
query: string;
|
|
date: string;
|
|
}
|
|
|
|
export const useSearchHistory = () => {
|
|
const [_searchHistory, setSearchHistory] = useLocalStorage<Search[]>("searchHistory", []);
|
|
|
|
const searchHistory = useMemo(() => {
|
|
return _searchHistory.toSorted((a, b) => {
|
|
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
|
});
|
|
}, [_searchHistory]);
|
|
|
|
return {
|
|
searchHistory,
|
|
setSearchHistory,
|
|
}
|
|
} |