Skip to content

Commit

Permalink
Merge branch 'main' into 188059193-day-slider-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanik committed Aug 8, 2024
2 parents e7c4a99 + a12e81a commit 8508f50
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useRef } from "react";
import { clsx } from "clsx";
import { ILocation } from "../types";
import { kInitialDimensions, kVersion, kPluginName, kDefaultOnAttributes, kSimulationTabDimensions, kDataContextName } from "../constants";
Expand All @@ -21,6 +21,8 @@ export const App: React.FC = () => {
const [dataContext, setDataContext] = useState<any>(null);

const { getUniqueLocationsInCodapData } = useCodapData();
// Store a ref to getUniqueLocationsInCodapData so we can call inside useEffect without triggering unnecessary re-runs
const getUniqueLocationsRef = useRef(getUniqueLocationsInCodapData);

useEffect(() => {
const initialize = async () => {
Expand All @@ -42,15 +44,15 @@ export const App: React.FC = () => {
const casesDeleted = values.operation === "selectCases" && values.result.cases.length === 0 && values.result.success;

if ( casesDeleted ) {
const uniqeLocations = await getUniqueLocationsInCodapData();
const uniqeLocations = await getUniqueLocationsRef.current();
if (uniqeLocations) setLocations(uniqeLocations);
}
};
addDataContextChangeListener(kDataContextName, casesDeletedFromCodapListener);
};

initialize();
}, [getUniqueLocationsInCodapData]);
}, []);

const handleTabClick = (tab: "location" | "simulation") => {
setActiveTab(tab);
Expand Down

0 comments on commit 8508f50

Please sign in to comment.