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