fix(search): restore history after hydration
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user