fix(buchhaltung): prevent form reset on query refetch during transaction edit
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { useQuery, useMutation } from '@tanstack/react-query';
|
||||
import {
|
||||
@@ -74,9 +74,12 @@ export default function BuchhaltungTransaktionForm() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [haushaltsjahre]);
|
||||
|
||||
// Pre-fill from existing transaction when editing
|
||||
const hasPrefilled = useRef(false);
|
||||
|
||||
// Pre-fill from existing transaction when editing — only once
|
||||
useEffect(() => {
|
||||
if (existing) {
|
||||
if (existing && !hasPrefilled.current) {
|
||||
hasPrefilled.current = true;
|
||||
setForm({
|
||||
haushaltsjahr_id: existing.haushaltsjahr_id,
|
||||
typ: existing.typ as 'einnahme' | 'ausgabe',
|
||||
|
||||
Reference in New Issue
Block a user