Skip to content

Instantly share code, notes, and snippets.

@emanueleDiVizio
Created June 1, 2020 17:33
Show Gist options
  • Save emanueleDiVizio/1fdde07f05d9dffea68b84924f17348e to your computer and use it in GitHub Desktop.
Save emanueleDiVizio/1fdde07f05d9dffea68b84924f17348e to your computer and use it in GitHub Desktop.
const lastShiftSelector = state => state.shifts.slice(-1)[0]
const useIsOnShift = () => {
const lastShift = useSelector(lastShiftSelector)
const currentTime = useCurrentTime()
const [isOnShift, setIsOnShift] = useState(false)
useEffect(() => {
if (lastShift) {
setIsOnShift(currentTime.isBefore(lastShift.endTime))
}
}, [currentTime])
return isOnShift
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment