Fine tune scan status behaviour

This commit is contained in:
Deluan
2020-11-12 16:12:31 -05:00
parent 0e7163eb2c
commit c09ba509b2
5 changed files with 76 additions and 26 deletions
+1
View File
@@ -21,4 +21,5 @@ export * from './StarButton'
export * from './Title'
export * from './SongBulkActions'
export * from './useAlbumsPerPage'
export * from './useInterval'
export * from './Writable'
+23
View File
@@ -0,0 +1,23 @@
// From https://overreacted.io/making-setinterval-declarative-with-react-hooks/
import { useEffect, useRef } from 'react'
export const useInterval = (callback, delay) => {
const savedCallback = useRef()
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback
}, [callback])
// Set up the interval.
useEffect(() => {
function tick() {
savedCallback.current()
}
if (delay !== null) {
let id = setInterval(tick, delay)
return () => clearInterval(id)
}
}, [delay])
}