Last active
January 8, 2021 22:43
-
-
Save tfiechowski/12b24db64c58870a3c18dd5a2b544457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useMemo, useState } from "react"; | |
import { useDebouncedCallback } from "use-debounce/lib"; | |
export const DEBOUNCED_BATCH_TIMEOUT = 500; | |
function hasPendingUpdates(batchUpdates) { | |
return Object.keys(batchUpdates).length > 0; | |
} | |
export function usePhotos({ photos: initialPhotos = [], onUpdate }) { | |
const [photos, setPhotos] = useState(initialPhotos); | |
const [pendingUpdates, setPendingUpdates] = useState({}); | |
const performUpdates = useDebouncedCallback( | |
async () => {}, | |
DEBOUNCED_BATCH_TIMEOUT, | |
{ maxWait: 2500 } | |
); | |
const updatePhotos = useCallback((itemsUpdates) => {}, []); | |
const currentPhotos = useMemo(() => {}, []); | |
return { | |
updatePhotos, | |
pendingUpdates, | |
photos: currentPhotos, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment