Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/gentle-pants-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
---

Increase the duration until data become stale for organization hooks.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ export const ActiveMembersList = () => {
return null;
}

const handleRoleChange = (membership: OrganizationMembershipResource) => (newRole: string) => {
return card
.runAsync(async () => {
return await membership.update({ role: newRole });
})
.catch(err => handleError(err, [], card.setError));
};
const handleRoleChange = (membership: OrganizationMembershipResource) => (newRole: string) =>
card.runAsync(() => membership.update({ role: newRole })).catch(err => handleError(err, [], card.setError));

const handleRemove = (membership: OrganizationMembershipResource) => async () => {
return card
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/src/react/hooks/usePagesOrInfinite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export const useWithSafeValues = <T extends PagesOrInfiniteOptions>(params: T |
} as T;
};

const cachingSWROptions = {
dedupingInterval: 1000 * 60,
focusThrottleInterval: 1000 * 60 * 2,
} satisfies Parameters<typeof useSWR>[2];

type ArrayType<DataArray> = DataArray extends Array<infer ElementType> ? ElementType : never;
type ExtractData<Type> = Type extends { data: infer Data } ? ArrayType<Data> : Type;

Expand Down Expand Up @@ -122,7 +127,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options,
// @ts-ignore
return fetcher?.(requestParams);
},
{ keepPreviousData },
{ keepPreviousData, ...cachingSWROptions },
);

const {
Expand Down Expand Up @@ -152,6 +157,7 @@ export const usePagesOrInfinite: UsePagesOrInfinite = (params, fetcher, options,
// @ts-ignore
return fetcher?.(requestParams);
},
cachingSWROptions,
);

const page = useMemo(() => {
Expand Down