Skip to content

Commit

Permalink
Merge pull request #265 from psteinroe/fix/remove-usememo
Browse files Browse the repository at this point in the history
fix: remove unnecessary useMemo
  • Loading branch information
psteinroe committed Aug 8, 2023
2 parents b4495da + 92caf9e commit 7bcbb9f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-balloons-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@supabase-cache-helpers/postgrest-swr": patch
---

fix: remove unnecessary useMemo calls
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,9 @@ function useInfiniteOffsetPaginationQuery<

const [currentPageIndex, setCurrentPageIndex] = useState(0);

const { data: parsedData, hasMore } = useMemo(() => {
return {
data: (data ?? []).map((p) => p.data),
hasMore:
Array.isArray(data) && data.length > 0 && data[data.length - 1].hasMore,
};
}, [data]);
const parsedData = (data ?? []).map((p) => p.data);
const hasMore =
Array.isArray(data) && data.length > 0 && data[data.length - 1].hasMore;

return {
pages: parsedData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function useOffsetInfiniteQuery<
Relationships
> | null,
config?: SWRInfiniteConfiguration & { pageSize?: number }
): UseInfiniteQueryReturn<Result> {
): UseOffsetInfiniteQueryReturn<Result> {
return useSWRInfinite<
Exclude<PostgrestResponse<Result>['data'], null>,
PostgrestError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function useOffsetInfiniteScrollQuery<
Relationships
> | null,
config?: SWRInfiniteConfiguration & { pageSize?: number }
): UseInfiniteScrollQueryReturn<Result> {
): UseOffsetInfiniteScrollQueryReturn<Result> {
const { data, setSize, size, isValidating, ...rest } = useSWRInfinite<
PostgrestHasMorePaginationResponse<Result>,
PostgrestError
Expand Down Expand Up @@ -106,16 +106,11 @@ function useOffsetInfiniteScrollQuery<
}
);

const { data: flatData, hasMore } = useMemo(() => {
return {
data: (data ?? []).flatMap((p) => p.data),
hasMore:
Array.isArray(data) && data.length > 0 && data[data.length - 1].hasMore,
};
}, [data]);
const hasMore =
Array.isArray(data) && data.length > 0 && data[data.length - 1].hasMore;

return {
data: flatData,
data: (data ?? []).flatMap((p) => p.data),
size,
setSize,
loadMore: hasMore ? () => setSize(size + 1) : null,
Expand Down

2 comments on commit 7bcbb9f

@vercel
Copy link

@vercel vercel bot commented on 7bcbb9f Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supabase-cache-helpers-react-query – ./examples/react-query

supabase-cache-helpers-react-query-git-main-psteinroe.vercel.app
supabase-cache-helpers-react-query.vercel.app
supabase-cache-helpers-react-query-psteinroe.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7bcbb9f Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

supabase-cache-helpers-swr-demo – ./examples/swr

supabase-cache-helpers-swr.vercel.app
supabase-cache-helpers-swr-demo-git-main-psteinroe.vercel.app
supabase-cache-helpers-swr-demo-psteinroe.vercel.app

Please sign in to comment.