Fix render-phase dispatch in FieldArrayForm

This commit is contained in:
2026-04-07 12:37:29 +01:00
parent 503a0b5b9a
commit dcdec08f6d
2 changed files with 32 additions and 2 deletions
+6 -2
View File
@@ -5,7 +5,7 @@ import _ from "lodash";
import useTranslation from "next-translate/useTranslation";
import Link from "next/link";
import { useRouter } from "next/router";
import React, { useMemo, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import "react-datepicker/dist/react-datepicker.css";
import Dropzone from "react-dropzone";
import { Field, FieldArray, change } from "redux-form";
@@ -1602,7 +1602,11 @@ export const FieldArrayForm = (props) => {
(showIfHasParentShowValue == parentField) != false &&
showIfHasParentShowValue;
!showIfHasParentShowValue && dispatch(change("appealForm", name, null));
useEffect(() => {
if (!showIfHasParentShowValue) {
dispatch(change("appealForm", name, null));
}
}, [dispatch, name, showIfHasParentShowValue]);
parentFieldShowOnValue;
const { handleSubmit, pristine, reset, submitting } = props;
+26
View File
@@ -3473,3 +3473,29 @@ Validation:
Follow-ups:
- Keep redux-form `fields.push/remove` calls event/effect-driven (not render-driven) in future slices.
---
### CL-097: 22500 `FieldArrayForm` render-phase dispatch warning hotfix
date: 2026-04-07
author: Cline
scope: `components/elements/index.js`
type: change
rationale: Fix React warning caused by dispatching redux-form state updates during `FieldArrayForm` render.
impact: No intended behavior change; clearing hidden FieldArray values remains intact but now executes in effect phase instead of render phase.
status: completed
Summary:
- Root cause: `dispatch(change("appealForm", name, null))` was called inline in render when parent condition was false.
- Fix: moved that dispatch into `useEffect` guarded by `!showIfHasParentShowValue`.
- Added `useEffect` import in `components/elements/index.js`.
Validation:
- `npx eslint components/elements/index.js` -> pass
Follow-ups:
- Continue avoiding dispatch/state mutations inside render for field visibility toggles.