Skip to content

Commit

Permalink
Adjust useForm to more gracefully handle page refreshes (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmartin-coforma authored Feb 12, 2025
1 parent 51ea441 commit 3fa9fd4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions services/ui-src/src/components/report/ReportPageWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect, useMemo, useState } from "react";
import { useEffect, useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { FormProvider, useForm } from "react-hook-form";
import { Box, Button, Divider, Flex, HStack, VStack } from "@chakra-ui/react";
import { FormPageTemplate } from "types";
import { getReport, useStore } from "utils";
import {
ReportModal,
Expand All @@ -25,10 +24,7 @@ export const ReportPageWrapper = () => {
const { reportType, state, reportId, pageId } = useParams();
const [isLoading, setIsLoading] = useState<boolean>(true);
const methods = useForm({
defaultValues: useMemo(() => {
const pageIndex = pageMap?.get(currentPageId ?? "")!;
return report?.pages[pageIndex];
}, [currentPageId]) as FormPageTemplate,
defaultValues: {},
shouldUnregister: true,
});

Expand All @@ -41,7 +37,7 @@ export const ReportPageWrapper = () => {
if (pageId) {
setCurrentPageId(pageId);
}
}, [pageId]);
}, [report, pageMap, pageId]);

const handleBlur = (data: any) => {
if (!report) return;
Expand Down

0 comments on commit 3fa9fd4

Please sign in to comment.