From 78c3f953985faa507bfc3e778b7e8926959f2184 Mon Sep 17 00:00:00 2001 From: Katrina Connors <32425204+katconnors@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:05:14 -0800 Subject: [PATCH] Fixes #468 (extra trial data) - update to prevent rerender (#484) * change to useRef * Update src/pages/benchmarks/[benchmark_id]/index.tsx --- src/pages/benchmarks/[benchmark_id]/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/benchmarks/[benchmark_id]/index.tsx b/src/pages/benchmarks/[benchmark_id]/index.tsx index e3706ca6..c4e5aa2a 100644 --- a/src/pages/benchmarks/[benchmark_id]/index.tsx +++ b/src/pages/benchmarks/[benchmark_id]/index.tsx @@ -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"; @@ -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(false); const hasInputChanged = currentTrial?.notes !== notesInputValue || @@ -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 && @@ -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