Skip to content

Commit 8aed3a6

Browse files
committed
Handle propsNeedConfiguring on field registration
1 parent 0befd3e commit 8aed3a6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/connect-react/examples/nextjs/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/connect-react/src/hooks/form-context.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
appPropErrors, arrayPropErrors, booleanPropErrors, integerPropErrors,
1414
stringPropErrors,
1515
} from "../utils/component";
16+
import _ from "lodash";
1617

1718
export type DynamicProps<T extends ConfigurableProps> = { id: string; configurableProps: T; }; // TODO
1819

@@ -374,6 +375,15 @@ export const FormContextProvider = <T extends ConfigurableProps>({
374375
}
375376
}
376377
// propsNeedConfiguring.splice(0, propsNeedConfiguring.length, ..._propsNeedConfiguring)
378+
379+
// Prevent useEffect/useState infinite loop by updating
380+
// propsNeedConfiguring only if there is an actual change to the list of
381+
// props that need to be configured.
382+
// NB: The infinite loop is triggered because of calling
383+
// checkPropsNeedConfiguring() from registerField, which is called
384+
// from inside useEffect.
385+
if (_propsNeedConfiguring && propsNeedConfiguring && _.isEqual(_propsNeedConfiguring, propsNeedConfiguring)) return;
386+
377387
setPropsNeedConfiguring(_propsNeedConfiguring)
378388
}
379389

@@ -382,6 +392,7 @@ export const FormContextProvider = <T extends ConfigurableProps>({
382392
fields[field.prop.name] = field
383393
return fields
384394
});
395+
checkPropsNeedConfiguring()
385396
};
386397

387398
// console.log("***", configurableProps, configuredProps)

0 commit comments

Comments
 (0)