Skip to content

Commit

Permalink
fix: skip Apollo query when folders state exists (#2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
leopuleo committed Dec 6, 2022
1 parent 78f581c commit 6a9f83c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/app-folders/src/hooks/useFolders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ export const useFolders = (type: string) => {
/**
* On first mount, call `listFolders`, which will either issue a network request, or load folders from cache.
* We don't need to store the result of it to any local state; that is managed by the context provider.
*
* IMPORTANT: we check if the folders[type] array exists: the hook can be used from multiple components and
* fetch the outdated list from Apollo Cache. Since the state is managed locally, we fetch the folders only
* at the first mount.
*/
listFolders(type);
}, []);
if (!folders[type]) {
listFolders(type);
}
}, [type]);

return useMemo(
() => ({
Expand Down

0 comments on commit 6a9f83c

Please sign in to comment.