DevTool error in console when appending to Field Array
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- react, typescript
Research direction
Start with the linked CodeSandbox, open the developer console, and click “Add Project” to reproduce and capture the missing error details. Trace the DevTool behavior triggered by appending to the field array and verify that the same action produces no console error when the issue is resolved.
Written by the indexing model from the issue text.
Description
Version Number
7.51.1
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/young-dust-9752gj?file=%2Fsrc%2FApp.js
Steps to reproduce
- Go to Code Sandbox
- Open up Dev Tools console
- Click on 'Add Project' button
Expected behaviour
There should be no errors:
import {
useForm,
FormProvider,
useFormContext,
useFieldArray,
} from "react-hook-form";
import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import { ErrorMessage } from "@hookform/error-message";
import { DevTool } from "@hookform/devtools";
const validationSchema = yup.object().shape({
firstName: yup.string().required("First Name is required"),
Projects: yup.array().of(
yup.object().shape({
name: yup.string().required("Project title required"),
})
),
});
export default function FormPage() {
const methods = useForm({
defaultValues: {
firstName: "",
Projects: [{ name: "" }],
},
resolver: yupResolver(validationSchema),
});
const { handleSubmit, control } = methods;
const { fields, append } = useFieldArray({
name: "Projects",
control,
});
return (
<>
<div>
<FormProvider {...methods}>
<form
onSubmit={handleSubmit(
(data) => console.log("Valid", data),
(errors) => console.log("NOT valid", errors)
)}
>
<div>
<h1>Form</h1>
<InputField
title="First Name"
id="firstName"
placeholder="Jhon"
/>
{fields.map((field, index) => (
<div
key={field.id}
style={{
paddingLeft: "25px",
marginTop: "15px",
marginBottom: "15px",
}}
>
<InputField
id={`Projects.${index}.name`}
title={`Project ${index + 1}`}
/>
</div>
))}
<div style={{ paddingLeft: "25px", marginBottom: "15px" }}>
<button type="button" onClick={() => append({ name: "" })}>
Add Project
</button>
</div>
<button type="submit">Submit</button>
</div>
</form>
</FormProvider>
<DevTool control={methods.control} />
</div>
</>
);
}
const InputField: React.FC<{
id: string,
title: string,
type?: string,
placeholder?: string,
}> = ({ id, title, type, placeholder }) => {
const {
register,
formState: { errors },
} = useFormContext();
const inputType = type ? type : "text";
return (
<div>
<label style={{ display: "block" }}>{title}</label>
<input
id={id}
type={inputType}
{...register(id)}
placeholder={placeholder}
/>
<ErrorMessage
errors={errors}
name={id}
render={({ message }) => <div style={{ color: "red" }}>{message}</div>}
/>
</div>
);
};
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
- 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 3/5 1-2 days Newbie friendliness 42/100
react-hook-form/devtools#226 · 3 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 ·
All issues in react-hook-form/devtools
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
0xMiden/bridge-portal#132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:tools bug good first issue help wanted priority:P2
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
TaewoooPark/Motifcode#14 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
newrelic-experimental/preflight#793 · 1 comment ·