Skip to content

Commit 7aef044

Browse files
committed
🐛 [#266] add prefix to the field key for AddressNL before accessing the formik context
When a user clicks on the "edit" button in the editgrid, react rerenders component as an isolated EditGridItem and creates an isolated formik context, where the field names have a prefix like "editgrid:0". Therefore we need to prefix the field name with 'useFieldConfig' hook in order to find the data in the new isolated context.
1 parent b2d109c commit 7aef044

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/registry/addressNL/deriveAddress.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {useFormikContext} from 'formik';
33
import {useEffect, useState} from 'react';
44
import {useAsync} from 'react-use';
55

6-
import {useDebounce, useFormSettings} from '@/hooks';
6+
import {useDebounce, useFieldConfig, useFormSettings} from '@/hooks';
77

88
import type {FormValues} from './types';
99
import {DEFAULT_POSTCODE_REGEX, HOUSE_NUMBER_REGEX} from './validationSchema';
@@ -20,6 +20,7 @@ const testValidInputs = (postcode: string, houseNumber: string): boolean => {
2020

2121
export const useDeriveAddress = (key: string, enabled: boolean): UseDeriveAddress => {
2222
const {getFieldProps, setFieldValue} = useFormikContext<FormValues>();
23+
key = useFieldConfig(key);
2324
const {value} = getFieldProps<AddressData>(key);
2425
const formSettings = useFormSettings();
2526
const [enableManualEntry, setEnableManualEntry] = useState<boolean>(false);

0 commit comments

Comments
 (0)