Skip to content

Commit

Permalink
removed useEffect hook
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijv256 committed Jan 23, 2024
1 parent 4c6cbcc commit bef2d3b
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/Components/Medicine/MedicineAdministrationSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next";
import useSlug from "../../../Common/hooks/useSlug";
import useQuery from "../../../Utils/request/useQuery";
import MedicineRoutes from "../routes";
import { useEffect, useMemo, useState } from "react";
import { useMemo, useState } from "react";
import { computeActivityBounds } from "./utils";
import useBreakpoints from "../../../Common/hooks/useBreakpoints";
import SubHeading from "../../../CAREUI/display/SubHeading";
Expand All @@ -13,7 +13,6 @@ import useRangePagination from "../../../Common/hooks/useRangePagination";
import MedicineAdministrationTable from "./AdministrationTable";
import Loading from "../../Common/Loading";
import ScrollOverlay from "../../../CAREUI/interactive/ScrollOverlay";
import { Prescription } from "../models";

interface Props {
readonly?: boolean;
Expand All @@ -29,7 +28,6 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {
const [showDiscontinued, setShowDiscontinued] = useState(false);

const filters = { is_prn, prescription_type: "REGULAR", limit: 100 };
const [prescriptionList, setPrescriptionList] = useState<Prescription[]>([]);

const { data, loading, refetch } = useQuery(
MedicineRoutes.listPrescriptions,
Expand All @@ -51,15 +49,10 @@ const MedicineAdministrationSheet = ({ readonly, is_prn }: Props) => {

const discontinuedCount = discontinuedPrescriptions.data?.count;

useEffect(() => {
if (!showDiscontinued) {
setPrescriptionList(data?.results ?? []);
} else {
const regularList = data?.results ?? [];
const discontinuedList = discontinuedPrescriptions.data?.results ?? [];
setPrescriptionList([...regularList, ...discontinuedList]);
}
}, [data, showDiscontinued]);
const prescriptionList = [
...(data?.results ?? []),
...(showDiscontinued ? discontinuedPrescriptions.data?.results ?? [] : []),
];

const { activityTimelineBounds, prescriptions } = useMemo(
() => ({
Expand Down

0 comments on commit bef2d3b

Please sign in to comment.