I'm using Field
with a custom component in react-final-form
. It looks like this:
<Field
component={DadataAddress}
name="address"
onSelect={suggestion => mutators.setValue(suggestion)}
query={values[name] && values[name].value}
/>
And here's the component itself:
const DadataAddress = ({
input: { onChange },
service,
onSelect,
...rest
}) => (
<DadataSuggestions
service={service}
onChange={event => onChange({ value: event })}
onSelect={onSelect}
/>
);
I would also like to move this line query={values[name] && values[name].value}
from the Field
to my custom component. But when I do it, I get an error:
Cannot read property 'address' of undefined
I guess, I need to define values
, but I don't know how to do it outside form
. I would really appreciate your help. Here is a codesandbox with an error.