Skip to content

Commit

Permalink
Keep setters stable, wrt analysis object
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfalke committed Feb 3, 2025
1 parent a5a9fda commit 65afb12
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/libs/eda/src/lib/core/hooks/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,20 @@ function useSetter<T>(
onAnalysisChange: AnalysisChangeHandler,
skipServerCreate = false
) {
const analysisRef = useRef(analysis);
useEffect(() => {
analysisRef.current = analysis;
});
return useCallback(
(nestedValue: T | ((nestedValue: T) => T)) => {
if (analysis == null) return; // TODO Should this throw an error?
onAnalysisChange(updateAnalysis(analysis, nestedValueLens, nestedValue), {
skipServerCreate,
});
if (analysisRef.current == null) return; // TODO Should this throw an error?
onAnalysisChange(
updateAnalysis(analysisRef.current, nestedValueLens, nestedValue),
{
skipServerCreate,
}
);
},
[analysis, nestedValueLens, onAnalysisChange, skipServerCreate]
[nestedValueLens, onAnalysisChange, skipServerCreate]
);
}

0 comments on commit 65afb12

Please sign in to comment.