Skip to content

Commit 731457b

Browse files
committed
fix: issues with record array field
1 parent 287ce75 commit 731457b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/Form/RecordArrayField.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ export const RecordArrayField = memo(function RecordArrayField({
2525
setValue: setArrayValue,
2626
value: arrayValue
2727
}: RecordArrayFieldProps) {
28-
const isFirstRenderRef = useRef(true);
28+
const fieldsetRef = useRef(fieldset);
2929
const { t } = useTranslation('libui');
3030

3131
const createNewRecord = () => Object.fromEntries(Object.keys(fieldset).map((fieldName) => [fieldName, undefined]));
3232

3333
useEffect(() => {
34-
if ((isFirstRenderRef.current && !arrayValue) || !isFirstRenderRef.current) {
34+
if (!arrayValue) {
3535
setArrayValue([createNewRecord()]);
3636
}
37-
isFirstRenderRef.current = false;
37+
}, []);
38+
39+
useEffect(() => {
40+
if (fieldsetRef.current !== fieldset) {
41+
setArrayValue([createNewRecord()]);
42+
fieldsetRef.current = fieldset;
43+
}
3844
}, [fieldset]);
3945

4046
if (!arrayValue) {

0 commit comments

Comments
 (0)