Fix la popover de recherche qui se ferme immédiatement

pull/2193/head
Jérémy Rialland 2022-07-04 18:41:33 +02:00 committed by Jérémy Rialland
parent 17910e2430
commit 5a482f7c3a
1 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import algoliasearch from 'algoliasearch/lite'
import { Spacing } from '@/design-system/layout'
import { useEffect } from 'react'
import { useEffect, useRef } from 'react'
import { Configure, Index } from 'react-instantsearch-dom'
import { RulesInfiniteHits } from './RulesInfiniteHits'
import { SearchBox } from './SearchBox'
@ -20,7 +20,13 @@ interface Props {
export default function SearchRulesAndSimulators({ closePopover }: Props) {
const location = useLocation()
useEffect(() => closePopover(), [location])
const prevLocation = useRef(location)
useEffect(() => {
if (prevLocation.current !== location) {
prevLocation.current = location
closePopover()
}
}, [closePopover, location])
return (
<SearchRoot