Fine tune scan status behaviour
This commit is contained in:
@@ -21,4 +21,5 @@ export * from './StarButton'
|
||||
export * from './Title'
|
||||
export * from './SongBulkActions'
|
||||
export * from './useAlbumsPerPage'
|
||||
export * from './useInterval'
|
||||
export * from './Writable'
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
Reference in New Issue
Block a user