Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from TaylorClay/fix-spinner-flashing
Browse files Browse the repository at this point in the history
Fix #23
  • Loading branch information
jrgarciadev authored May 23, 2022
2 parents 2750987 + d7091e8 commit 75c9b5a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions website/src/components/Loader/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { useEffect, useState } from 'react';
import { connectStateResults } from 'react-instantsearch-dom'
import { StyledLoader } from './styles'

const Loader = connectStateResults(({ isSearchStalled }) =>
isSearchStalled ? <StyledLoader /> : null
)
const SPINNER_DELAY = 200 // ms

const Loader = connectStateResults(({ isSearchStalled }) => {
const [canShowSpinner, setCanShowSpinner] = useState(false)

useEffect(() => {
setTimeout(() => {
setCanShowSpinner(true);
}, SPINNER_DELAY)
}, [canShowSpinner, setCanShowSpinner])

return canShowSpinner && isSearchStalled ? <StyledLoader /> : null
});

export default Loader

1 comment on commit 75c9b5a

@vercel
Copy link

@vercel vercel bot commented on 75c9b5a May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.