Skip to content

Commit

Permalink
chore: memoized indexes in formfield to prevent unneccessary updates
Browse files Browse the repository at this point in the history
Related to #1102
  • Loading branch information
Skaiir committed Apr 8, 2024
1 parent 2f9cae0 commit f809482
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/form-js-viewer/src/render/components/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FormContext, FormRenderContext } from '../context';

import {
useCondition,
useDeepCompareMemoize,
useReadonly,
useService
} from '../hooks';
Expand All @@ -19,7 +20,7 @@ const noop = () => false;
export function FormField(props) {
const {
field,
indexes,
indexes: _indexes,
onChange
} = props;

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

const { formId } = useContext(FormContext);

const indexes = useDeepCompareMemoize(_indexes || {});

// track whether we should trigger initial validation on certain actions, e.g. field blur
// disabled straight away, if viewerCommands are not available
const [ initialValidationTrigger, setInitialValidationTrigger ] = useState(!!viewerCommands);
Expand Down Expand Up @@ -134,7 +137,7 @@ export function FormField(props) {
}

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

const formFieldElement = (
<FormFieldComponent
Expand Down

0 comments on commit f809482

Please sign in to comment.