Multi step form or conditional rendering with DevTool console get an error Cannot update a component (`FormItemTest`) while rendering a different component (`FormItemTest`). To locate the bad setState() call inside `FormItemTest`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- devtools
Research direction
Start with the provided Demo reproduction using FormProvider, conditional Step2 rendering, getStep(step), and . Reproduce the warning with DevTool enabled, then inspect the DevTool component and its control subscription or rendering path. Done means the multi-step example no longer reports the setState-during-render warning while DevTool remains enabled.
Written by the indexing model from the issue text.
Description
The collection of fields in react hook form meets expectations. Confirmed to be a bug in DevTool. when I annotate DevTool,no more errors reported.
this is example code
import {
useForm,
FormProvider
} from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { DevTool } from '@hookform/devtools';
import FormItemTest from '~/components/form/FormItemTest';
import {
useState
} from 'react';
import * as z from 'zod';
const schema = z.object({
step1: z.string(),
step2: z.string()
});
function Step1() {
return (
<FormItemTest name='step1' />
)
}
function Step2() {
return (
<FormItemTest name='step2' />
)
}
function getStep(step: number) {
switch (step) {
case 0:
return <Step1 />;
case 1:
return <Step2 />;
default:
return null;
}
}
export default function Demo() {
const [show, setShow] = useState(false);
const [step, setStep] = useState(0);
const methods = useForm({
resolver: zodResolver(schema),
mode: 'onChange'
});
const onSubmit = methods.handleSubmit(values => {
console.log(values);
});
return (
<div>
<FormProvider {...methods}>
<form>
<Step1 />
{show && <Step2 />}
{getStep(step)}
</form>
</FormProvider>
<DevTool control={methods.control} />
<button onClick={() => setShow(s => !s)}>Toggle Step2</button>
<button onClick={onSubmit}>Submit</button>
<button onClick={() => setStep(s => s + 1)}>Next Step</button>
</div>
)
}
- Dominant language
- TypeScript
- Stars
- 670
- Forks
- 55
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react-hook-form/devtools
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
react-hook-form/devtools#234 · 1 comment · 5 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
react-hook-form/devtools#223 · 2 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
react-hook-form/devtools#212 · 5 comments · 8 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
react-hook-form/devtools#208 · 13 comments · 21 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
react-hook-form/devtools#207 · 6 comments · 1 reaction ·
All issues in react-hook-form/devtools
Similar issues
-
clawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#616 ·
-
ZCode 3.14.3 に対応する Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
supermomonga/zcode-acp#24 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
growthbook/growthbook#7100 ·
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100