Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite re-rendering connected with defaultValue #10413

Open
bookin opened this issue Dec 14, 2024 · 2 comments
Open

Infinite re-rendering connected with defaultValue #10413

bookin opened this issue Dec 14, 2024 · 2 comments

Comments

@bookin
Copy link

bookin commented Dec 14, 2024

Face in few places of my code with problem that when TextInput has defaultValue, or BooleanInput has disabled=true it give Infinite re-rendering.

As I understood problem somewhere in the - useApplyInputDefaultValues

The simplest example:

const Test: FC = () => {
	return (
		<SimpleForm>
			<BooleanInput
				label={'Chekbox'}
				source={'isCheckbox'}
				disabled={true}
			/>
		</SimpleForm>
	);
};

In this case I see infinite re-renders with warning - Warning: Cannot update a component (SaveButton) while rendering a different component (BooleanInput).

If use const form = useForm(); and <FormProvider {...form}> no warning, but still re-rendering

Error happens when disabled={true}, if set false it works

For TextInput I don't have example, I faced with it in using MUI DataGrid in the columns.renderCell. But I think problem the same.

Environment

  • React-admin version: 5.4.2
  • React version: 18.3.1
  • Hook Form: 7.54.1
@djhi
Copy link
Collaborator

djhi commented Dec 16, 2024

Thanks for reporting this. Please provide a sample application showing the issue, preferably a sandbox forked from

@slax57
Copy link
Contributor

slax57 commented Dec 16, 2024

FTR: we had several issues in the past using disabled inputs with react-hook-form. That's why we introduced a readOnly prop on all input components, and we now recommend to use it instead of disabled.
It may solve your issue.

References:
#9498
#9378
#9365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants