Skip to content

Commit

Permalink
Reset form Values on borehole change
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Sep 26, 2024
1 parent d385603 commit 37ded28
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "react";
import { FC, useEffect } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { Card } from "@mui/material";
import { CardContent } from "@mui/material/";
Expand Down Expand Up @@ -26,11 +26,16 @@ const ElevationSegment: FC<ElevationSegmentProps> = ({ borehole, user, updateCha

const formMethods = useForm({
mode: "all",
defaultValues: borehole.data,
});
// --- Derived states ---
const isEditable: boolean =
borehole?.data.role === "EDIT" && borehole?.data.lock !== null && borehole?.data.lock?.id === user?.data.id;

useEffect(() => {
formMethods.reset(borehole.data);
}, [borehole, formMethods]);

return (
<FormSegmentBox>
<FormProvider {...formMethods}>
Expand Down

0 comments on commit 37ded28

Please sign in to comment.