Skip to content

Instantly share code, notes, and snippets.

@tfiechowski
Last active January 8, 2021 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfiechowski/12b24db64c58870a3c18dd5a2b544457 to your computer and use it in GitHub Desktop.
Save tfiechowski/12b24db64c58870a3c18dd5a2b544457 to your computer and use it in GitHub Desktop.
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