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, limit,
storageKey, storageKey,
}: UseSearchHistoryOptions) { }: UseSearchHistoryOptions) {
const [items, setItems] = React.useState<readonly string[]>(() => // Keep the server render and the client's first render identical. Persisted
readSearchHistory(storageKey, limit) // history is restored by the effect after hydration.
) const [items, setItems] = React.useState<readonly string[]>([])
React.useEffect(() => { React.useEffect(() => {
const syncFromStorage = () => setItems(readSearchHistory(storageKey, limit)) const syncFromStorage = () => setItems(readSearchHistory(storageKey, limit))