RFC: V8 #7433
Replies: 19 comments 105 replies
-
One issue with this is when I need to update a field array index and I'm within a nested component. For example I wanted to update a field array index from within
Inside the component, I can easily grab I would rather use the |
Beta Was this translation helpful? Give feedback.
-
Proposal for field array context API: https://codesandbox.io/s/react-hook-form-v7-form-context-forked-7ng26?file=/src/index.js import React from "react";
import ReactDOM from "react-dom";
import { useForm, FormProvider, useFieldArray } from "./src";
import Test from "./Test";
import "./styles.css";
function App() {
const methods = useForm();
const { register, handleSubmit } = methods;
const testFieldArray = useFieldArray({
name: "data",
control: methods.control
});
console.log("render...");
return (
<FormProvider
{...methods}
arrays={{
test: testFieldArray
}}
>
<form onSubmit={handleSubmit((data) => console.log(data))}>
<label>Test</label>
<input {...register("test", { required: true })} />
<label>Nested Input</label>
<Test />
<input type="submit" />
</form>
</FormProvider>
);
}
export default function Test() {
const methods = useFormContext();
return (
<>
<input {...methods.register("bill")} />
{methods.arrays.test.fields.map((field, index) => {
return (
<input key={field.id} {...methods.register(`data.${index}.test`)} />
);
})}
<button onClick={() => methods.fieldArrays.test.append({ test: "data" })}>
append
</button>
</>
);
} |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if I'm just missing something here, but it seems like the direction the library is moving is to separate methods that alter field array fields vs regular fields. If this is true, I like this but I feel like some things are missing from the field array methods if this is the case:
By reset I mean the ability to not only change the default value but the metadata as well. With conditionally rendered fields in field arrays, I'm not seeing too many options other than I'm not sure if it makes more sense to add new methods or update methods like |
Beta Was this translation helpful? Give feedback.
-
cc @Moshyfawn you may want to be participate and aware of the general direction with v8. |
Beta Was this translation helpful? Give feedback.
-
useFieldArray ^ |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how I feel about this. Yes, it is less verbose but less verbose isn't always better. I like prefixing booleans with is and should because it's more readable and this is a big breaking change for not much benefit in my opinion. |
Beta Was this translation helpful? Give feedback.
-
This is just my personal opinion, I want to keep using |
Beta Was this translation helpful? Give feedback.
-
What do you think about starting to emit console warnings for these cases? Like, for RHF usage that's "discouraged"? |
Beta Was this translation helpful? Give feedback.
-
The new field path prevents registrations on conditional fields https://codesandbox.io/s/agitated-frost-hz9gcx?file=/src/App.tsx Is there a different method for registering to those now? |
Beta Was this translation helpful? Give feedback.
-
Kinda a breaking change, but what do you think about renaming |
Beta Was this translation helpful? Give feedback.
-
I am trying version 8 and I have a question about the I have been thinking about this but wouldn't it be easier if field was represented as I can work on it if you give me greenlight. |
Beta Was this translation helpful? Give feedback.
-
propose to change reset optional API: #8233 (reply in thread) |
Beta Was this translation helpful? Give feedback.
-
Is there a replacement for If you toggle v7/v8 here, the autocomplete enters/disappears: https://codesandbox.io/s/react-hook-form-js-forked-5r2bu3?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
-
V8 is looking great, thanks for the hard work. I'm not aware of any other library supporting type safe subforms. I've encountered a small type regression though:
This makes passing register potentially hazardous. |
Beta Was this translation helpful? Give feedback.
-
Discussed in #8510, |
Beta Was this translation helpful? Give feedback.
-
whats the state of v8 ? what's the estimated time for releasing v8 ? |
Beta Was this translation helpful? Give feedback.
-
Hi folks, reading back through all of the progress on v8 now. We're looking to make the switch from Formik ASAP but the circular dependency issue with Looking at 4.9 it seems like the solution at https://stackoverflow.com/questions/58434389/typescript-deep-keyof-of-a-nested-object/58436959#58436959 pretty much hits what we need, no? Happy to assist however I can. |
Beta Was this translation helpful? Give feedback.
-
I've seen this in a few comments (#9954 (comment) and #9400 (comment)) and it scares me 😬 Say I have the following form:
And I want to have Currently I'd do:
But if I understand the proposal correctly, I'd need to move away from |
Beta Was this translation helpful? Give feedback.
-
Hi team, happy new year - are there any updates to the status of v8 for 2025? In particular we are interested in the ts performance improvements. Based on #5941 (comment) it seems the minimum tsc version would have to be bumped from |
Beta Was this translation helpful? Give feedback.
-
V8
We will try to ensure good backward compatibility, which means we will try to ship most of the new features at V7 and migrate over to V8.
reset
remove
keepIsValid
forreset
optionsreset({ data: 'test' }, { - keepIsValid: true })
Rationale:
valid
formState
should always reflect the current form valid state instead of being manipulated and causing unexpected behavior.Rationale: by providing what your form should be reset to ease the issue with
undefined
value and also making sure type safety is much easy measured instead ofDeepPartial
useFieldArray
prop
keyName
will be removed and no longer requiredRationale: field id is no longer required in V7 https://github.com/react-hook-form/react-hook-form/releases/tag/v7.23.0 and this is so we can reduce configuration
useController
&getFieldState
remove fieldState
invalid
Rationale: API consistency #8195 user should be able to use the error object directly and avoid this inconsistency
useFieldArray
considering changing key name from
id
tokey
Rationale: to ease the
id
value overwrite issues.✨
useFieldArray
prop
rules
will be added for field array level validationclose: #6879
Rationale: now that the errors object type is improved and we can support field array root level error object. Adding
root
to the array index may affect the array prototype, but considering the usage of the errors object, I think it's a worthy trade-off rather introduce a separate node for field array root level errors.handleSubmit
will inferformValues
andUseFormHandleSubmit
generic is no longer required.onValid
andonInvalid
payload both will bereadOnly
Don't expose internal errors reference in handleSubmit #7718useForm
'sdefaultValues
is provided, then it's no longer deep partial to support better type checking (this is not impact inlinedefaultValue
/defaultChecked
)NesetedValue
and usegetFieldState
for neseted object input insteadTriggerConfig
rename toTriggerOptions
SetValueConfig
rename toSetValueOptions
PR: #5941
✨ Added
⚠️ Breaking change
🥼 Change
Beta Was this translation helpful? Give feedback.
All reactions