Skip to content

Commit

Permalink
fix: make sure to persist the current search
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Nov 21, 2023
1 parent 349ed0f commit f94d2e4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib/adapters/static/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { memo, useMemo } from 'react'
import React, { memo, useMemo, useRef } from 'react'
import {
HistoryManagement,
StoreContext,
createGeschichte,
} from '../../store.js'
import { createSearch } from '../../utils.js'

interface Props {
readonly search?: string
Expand All @@ -13,17 +14,20 @@ const StaticGeschichteProvider = ({
search,
children,
}: React.PropsWithChildren<Props>) => {
const thisSearch = useRef(search)
const historyInstance: HistoryManagement = useMemo(() => {
return {
initialSearch: () => search || '?',
push: async () => {
initialSearch: () => thisSearch.current || '',
push: async (query) => {
thisSearch.current = createSearch(query)
return
},
replace: async () => {
replace: async (query) => {
thisSearch.current = createSearch(query)
return
},
}
}, [search])
}, [thisSearch])

const value = useMemo(
() => createGeschichte(historyInstance),
Expand Down

0 comments on commit f94d2e4

Please sign in to comment.