Skip to content

Commit

Permalink
Fixes #468 (extra trial data) - update to prevent rerender (#484)
Browse files Browse the repository at this point in the history
* change to useRef

* Update src/pages/benchmarks/[benchmark_id]/index.tsx
  • Loading branch information
katconnors authored Jan 3, 2025
1 parent f25a333 commit 78c3f95
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pages/benchmarks/[benchmark_id]/index.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 Counter from "@/components/counter/counter";
import ParaNav from "@/components/paraNav/ParaNav";
import Link from "next/link";
Expand Down Expand Up @@ -71,7 +71,7 @@ const BenchmarkPage = () => {
const [currentTrialIdx, setCurrentTrialIdx] = useState(0);
const currentTrial = task?.trials[currentTrialIdx] || null;

const [trialAdded, setTrialAdded] = useState(false);
const trialAddedRef = useRef<boolean>(false);

const hasInputChanged =
currentTrial?.notes !== notesInputValue ||
Expand Down Expand Up @@ -108,7 +108,7 @@ const BenchmarkPage = () => {
// Creates a new data collection instance (if there are none in progress)
useEffect(() => {
if (
!trialAdded &&
!trialAddedRef.current &&
!addTrialMutation.isLoading &&
!taskIsLoading &&
task &&
Expand All @@ -121,9 +121,9 @@ const BenchmarkPage = () => {
unsuccess: 0,
notes: "",
});
setTrialAdded(true);
trialAddedRef.current = true;
}
}, [task, addTrialMutation, taskIsLoading, trialAdded]);
}, [task, addTrialMutation, taskIsLoading]);

const handleUpdate = (updates: DataUpdate) => {
//Can only update if we're on the most recent trial
Expand Down

0 comments on commit 78c3f95

Please sign in to comment.