fix(search): restore history after hydration

This commit is contained in:
Maofeng
2026-09-20 16:22:21 +08:00
parent f442c07dbf
commit a57fdbe7c6
+3 -3
View File
@@ -9,9 +9,9 @@ export function useSearchHistory({
limit,
storageKey,
}: UseSearchHistoryOptions) {
const [items, setItems] = React.useState<readonly string[]>(() =>
readSearchHistory(storageKey, limit)
)
// Keep the server render and the client's first render identical. Persisted
// history is restored by the effect after hydration.
const [items, setItems] = React.useState<readonly string[]>([])
React.useEffect(() => {
const syncFromStorage = () => setItems(readSearchHistory(storageKey, limit))