Skip to content

Commit f809482

Browse files
committed
chore: memoized indexes in formfield to prevent unneccessary updates
Related to #1102
1 parent 2f9cae0 commit f809482

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/form-js-viewer/src/render/components/FormField.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FormContext, FormRenderContext } from '../context';
77

88
import {
99
useCondition,
10+
useDeepCompareMemoize,
1011
useReadonly,
1112
useService
1213
} from '../hooks';
@@ -19,7 +20,7 @@ const noop = () => false;
1920
export function FormField(props) {
2021
const {
2122
field,
22-
indexes,
23+
indexes: _indexes,
2324
onChange
2425
} = props;
2526

@@ -44,6 +45,8 @@ export function FormField(props) {
4445

4546
const { formId } = useContext(FormContext);
4647

48+
const indexes = useDeepCompareMemoize(_indexes || {});
49+
4750
// track whether we should trigger initial validation on certain actions, e.g. field blur
4851
// disabled straight away, if viewerCommands are not available
4952
const [ initialValidationTrigger, setInitialValidationTrigger ] = useState(!!viewerCommands);
@@ -134,7 +137,7 @@ export function FormField(props) {
134137
}
135138

136139
const domId = `${prefixId(field.id, formId, indexes)}`;
137-
const fieldErrors = get(errors, [ field.id, ...Object.values(indexes || {}) ]) || [];
140+
const fieldErrors = get(errors, [ field.id, ...Object.values(indexes) ]) || [];
138141

139142
const formFieldElement = (
140143
<FormFieldComponent

0 commit comments

Comments
 (0)