Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: useSwr needs to be called conditionally

Marc Seitz02c84ab17ca1
diff --git a/lib/swr/use-document.ts b/lib/swr/use-document.ts
index f2f30b60..d4c5d59f 100644
--- a/lib/swr/use-document.ts
+++ b/lib/swr/use-document.ts
@@ -124,15 +124,10 @@ export function useDocumentProcessingStatus(documentVersionId: string) {
}
export function useDocumentThumbnail(pageNumber: number, documentId: string) {
- if (pageNumber === 0) {
- return {
- data: null,
- loading: false,
- error: null,
- };
- }
const { data, error } = useSWR<{ imageUrl: string }>(
- `/api/jobs/get-thumbnail?documentId=${documentId}&pageNumber=${pageNumber}`,
+ pageNumber === 0
+ ? null
+ : `/api/jobs/get-thumbnail?documentId=${documentId}&pageNumber=${pageNumber}`,
fetcher,
{
dedupingInterval: 1200000,
@@ -143,6 +138,14 @@ export function useDocumentThumbnail(pageNumber: number, documentId: string) {
},
);
+ if (pageNumber === 0) {
+ return {
+ data: null,
+ loading: false,
+ error: null,
+ };
+ }
+
return {
data,
loading: !error && !data,