Using version 7.0.2 for all kendo-react dependencies.
I'm trying to use a custom Input component for a form Field component in order to achieve a custom onBlur functionality, which will set a state variable in parent component of the Field. The following code causes an infinite re-render for the custom input component:
If I move the UserEmailInput component outside of the GroupUser component, the infinite re-render is resolved, but I lose the ability to set a the state variable in GroupUser. I could feasibly use a React Context for this, but I'd prefer to use those as sparingly as possible.
Can anyone advise me on this infinite re-render issue, and how I might be able to mitigate it without moving my custom input field outside of the component where the Field is rendered, and where my state variable needs to be set?
I'm trying to use a custom Input component for a form Field component in order to achieve a custom onBlur functionality, which will set a state variable in parent component of the Field. The following code causes an infinite re-render for the custom input component:
export const User = () => {
const [existingUser, setExistingUser] = React.useState({});
const handleUserResponse = (result: any) => {
if (result.data) {
setExistingUser(result.data[0]);
}
};
const UserEmailInput = (props: FieldRenderProps) => {
React.useEffect(() => {
console.log("UserEmailInput Re-Render");
}, []);
const [value, setValue] = React.useState<string>('');
const emailOnBlur = () => {
fetch(...).then((response: any) => {
console.log(response);
setExistingUser(response.data[0]);
};
};
return (
<FormMaskedTextBox
{...props}
onChange={(e: any) => { setValue(e.value); }}
onBlur={emailOnBlur}
/>
);
};
return (
<div style={{ marginTop: '5px', marginBottom: '5px' }}>
<Card>
//Form component lives in parent component.
<Field
name={"email"}
label={"E-mail:"}
component={UserEmailInput}
validator={[
requiredValidator("E-mail"),
lengthValidator("E-mail", 255),
regexValidator("E-mail", emailRegex)
]}
id="emailID"
/>
</CardBody>
</Card>
</div>
);
};
Can anyone advise me on this infinite re-render issue, and how I might be able to mitigate it without moving my custom input field outside of the component where the Field is rendered, and where my state variable needs to be set?