V7 #3714
Replies: 59 comments 404 replies
-
As long that useController is following ;) I like this new hook!! Trying right now to add typescript field for custom component with useControllerProps |
Beta Was this translation helpful? Give feedback.
-
Very nice! We rolled out auto-generated hooks with rtk-query using the typed literals and they're great. Looking forward to this release. Congrats and awesome work! 💯 |
Beta Was this translation helpful? Give feedback.
-
Continuing conversation from #3719 (comment)
There are multiple issues raised in #3719:
Avoiding unregistering is good. However, my ultimate goal is only to change the underlying default values and allow react-hook-form to compute dirty/valid state accordingly. I don't want to reset the values. I don't want to reset anything, unless you consider changing the default values to be a "reset". Allowing the resetting of Another example, what happens if I say that a field is In short, I'm not sure I understand the reason to give the user complete control over the state machine so that non-sensical states can be created and it's unclear how I would address the situations described in #3719 with that ability. |
Beta Was this translation helpful? Give feedback.
-
@jorisre should we expose |
Beta Was this translation helpful? Give feedback.
-
can we not assume the error While we are at this has anyone tried to pass an object to |
Beta Was this translation helpful? Give feedback.
-
Hi, the My problem is that there's no way to watch all changes AND detect what's changed. The new |
Beta Was this translation helpful? Give feedback.
-
I've got a thought on controlled/uncontrolled components, which I think might go well with the new When creating reusable uncontrolled components, being able to pass the result of register is really useful because it's easy. But one thing you don't get is access Passing So what I'm wondering: Is there any way to combine function App() {
const { control } = useForm({});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...control(name, {required: true}).field} />
<InputComponent control={control(name, {required: true})} />
</form>
);
} Perhaps Anyway, just some food for thought. |
Beta Was this translation helpful? Give feedback.
-
Landed here from the docs page to read more about the deprecation of Thanks |
Beta Was this translation helpful? Give feedback.
-
Regarding:
I agree omitting "Fields" is the right choice. My concern is however, if I suggest
This can avoid people coming to this code in a project, and thinking that the input needs to be sanitized further, e.g. In the docs:
Here I question if we really need to explicitly tell the user to provide a Hopefully this help you, Bill. I liked everything else. |
Beta Was this translation helpful? Give feedback.
-
Small typo: 'rename
|
Beta Was this translation helpful? Give feedback.
-
It would be nice to improve the error reading. As you focus more on typescript, it would be good if errors could contain more information of why a form is not valid, and have type-related errors too. |
Beta Was this translation helpful? Give feedback.
-
I receive empty error messages
On Sat, 16 Jan 2021 at 5:00 pm, Bill<[email protected]> wrote:
isn't that in the error object?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
Just wondering what the timeline for this is. The changes to persisting values are very useful to me so wondering when I can start using this in my projects. Will a beta release be available on NPM first? |
Beta Was this translation helpful? Give feedback.
-
Please do not do its deprecated, its really needed functionality const form = useForm({ ..., shouldUnregister: false })
return (
<FormProvider {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
{formSteps[currentStepIndex]}
) |
Beta Was this translation helpful? Give feedback.
-
The plan is to keep values in the form state that are unmounted. I'm wondering if this would also be true for So let's say I have a field array. A common use case is the ability to hide or conceal a field array elements (a group of inputs) to use screen space better. When this happens, the element is currently removed from the field array. This breaks |
Beta Was this translation helpful? Give feedback.
-
I wanted to bring up the topic of syncing field array values with form values and an issue I'm facing regarding this. Let's say we have a field array and we use append to add a value. So something like this:
After doing this the new element will be placed inside the What are the issues with |
Beta Was this translation helpful? Give feedback.
-
I've been using React Hook Form and love the developer experience! I just saw in the docs that the |
Beta Was this translation helpful? Give feedback.
-
Hello, How am I supposed to define a custom onChange callback in v7? Thx for your work on v7 :) |
Beta Was this translation helpful? Give feedback.
-
Looks like the V7 beta is getting stable! Aim to release an RC version at 2 years birthday, 6th Mar. |
Beta Was this translation helpful? Give feedback.
-
Hello, gotta say I really am liking this new version! I have been experimenting with the current beta version, and have got a problem with the I saw that the I ask because I only have the I thought the Here is a code sample:for initialData: AddressFormData = { title: "test" };
Whatever you trigger Doing the following works, but since I add fields dynamically at some forms, it would not suffice:
|
Beta Was this translation helpful? Give feedback.
-
hey react-hook-form folks! excellent work on v7! I have a small request/question that i've come across migrating a typscript code base to from a different form library to In code: // this example uses the popular react-intl package but i imagine react elements would be often a choice for translation.
const REQUIRED_ERROR_MESSAGE = <FormattedMessage id="someID" defaultMessage="This is a required field!" />;
function MyForm() {
const { register, formState, handleSubmit } = useForm<{ name: string }>();
return (
<form onSubmit={handleSubmit((values) => console.log(values))}>
<input type="text" {...register("name", { required: REQUIRED_ERROR_MESSAGE })} />
{formState.errors.name?.message}
<input type="submit" />
</form>
);
} |
Beta Was this translation helpful? Give feedback.
-
V7 RC released. expected next month release the final v7. I wouldn't expect much of a breaking change from RC onwards. |
Beta Was this translation helpful? Give feedback.
-
Hey, Loving the new v7! Is this also intended for Here is an example of what I mean, if you change the field and then click submit you will only see the dirtyFields if you console logged before hand. Also is console.log the best method of getting round this? Love the feature btw, it allows me to do partial submissions rather than submitting the whole form. |
Beta Was this translation helpful? Give feedback.
-
Is there a working example of v7 integration with existing form or example of custom components where input is wrapped in it? https://react-hook-form-website-git-v7-bluebill1049.vercel.app/get-started#Integratinganexistingform This seems to be it, but I can't get it to work. Type Error in the line below: register is not a function.
Codepen linked in the docs is written for v6 with passing register to ref property and doesn't really apply here. |
Beta Was this translation helpful? Give feedback.
-
Hello,
How to use |
Beta Was this translation helpful? Give feedback.
-
Hi, I really like the new API and wanted to ask if you plan to improve typings for a
This means there is no type-safety for the value and onChange handler so basically, any custom input will need a bit more caution to not introduce bugs in the app. However, other parts of the API such as |
Beta Was this translation helpful? Give feedback.
-
Thank you for everyone's participartion. V7 is released. |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
i am using react hook form version 6, but i havent seen image and files input using controller into backend django |
Beta Was this translation helpful? Give feedback.
-
can I use version 7 with react version 16.13.1? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
Typescript is getting more and more populated among the community, and it's our responsibility to improve type support over time. TS 4.1.0: https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types is totally a game-changer for us to build strict typed form, and that's one of the main drivers for us to produce another major version so we can leverage this awesome feature to provide users even better typescript support.
Documentation V7
https://react-hook-form-website-git-v7.bluebill1049.now.sh/
Vision
📖 (DX) Strictly typed form
🏋🏻♀️ Reduce package size
🏎 Performance
💁♂️ Simplicity and consistency
Proposal
register
We really want to guarantee type-safe with
register
API, the current implementation does have difficulty achieving this because there is no simple way for typescript to extract name attribute inside input element asref
, so we plan to move away from the current way of register native input. here is the proposal:By doing the above, which means we can type the input name correctly with template literal against your input data type.
MutationObserver
will be removed as well.[]
for the array field, this is to be consistent with typescript usage.🟢 Better fast refresh support
🟢 Made strict type checking possible
🟢 Less to type and consistent API with useFieldArray
🟢 Consistent with React Native API
🔴 Breaking change
🔴 Required to invoke
unreigster
when inputs get unmountedvalueAs
Currently
valueAs
is running at submission value, this is causing inconsistency withtype
. This will be changed at V7, wherevalueAs
will always be run before the build-in validator andresolver
.🟢 Type consistency
🔴 Breaking change
Controller
remove
as
prop and provide a single solution withrender
prop,as
works well with standard controlled input which exposedonChange
,onBlur
andvalue
, however, there are cases which are not going to work well and it's confusing to give users too many options.onFocus
prop is removed, use theref
prop from thefield
object.change
render
'sprops
to align withuseController
updated meta:
🟢 Consistent API with
useController
🟢 Less way to think about making components
🔴 More to type
🔴 Breaking change
reset
reset
is one of the most powerful APIs in hook form, however, it does comes with its own limitation and yet more functionality can be explored. We want to make it as easy as it today for beginner users and still have the capability for advanced users, so we would like to enhance the second argument from the current API.🟢 declarative on the second argument on what's getting reset
🔴 Breaking change
🔴 Verbose
Related:
#3719
getValues
There have been quite a few questions around why
getValues()
is not returningdefaultValues
, we will makegetValues
returndefaultValues
before the render (before inputs mounted).🟢 Users can retrieve
defaultValues
before inputs get mounted.🔴 Breaking change
append
insert
prepend
The current above API design is lack of extending, the second argument as
boolean
is not scalable for new options. we are proposing to change that into an object of options.🟢 More powerful and extensible
🔴 Breaking change
Related:
#2155
#3525
#2155
resolver
resolver is a powerful way to integrate with external validation libs, and we want to further improve its functionality and robustness. We are introducing the third argument which gives other libs like more insight into the validation.
🟢 More powerful and extensible
🔴 Breaking change
Related:
#3110
#3538
watch
allow
watch
to subscribe to inputs change without trigger re-render.watch
'sdefaultValue
will only get printed on the initial invoke before render.watch
array
will returnarray
instead ofobject
🟢 Flexible with subscribed inputs
🟢 Type alignment
🔴 Increase bundle size
Related:
#912
trigger
trigger
will no longer return validation result (as Promise), instead of subscribing toerrors
formState
, each time calling trigger will trigger a re-render as well.🟢 Reduce
trigger
's complexity and keep it simple and focus only on doing one goal, that's to trigger validation.🔴 Breaking change and more to type
errors
One of the limitations right now is
errors
or anyformState
will always re-render at the root of the App/Form, we would like to improve that and give users the opportunity to isolate that re-render within components level, which means we want to wraperrors
within theproxy
as well, so we can skip any re-render if users are not subscribed to theerrors
formState
.🟢 Allow hook form to precisely know which state to subscribe
🔴 Breaking change and more to type
useFormState
This new hook will allow you to subscribe
formState
update at the component level instead of the root level where you initialized theuseForm
. Users will have the capability to subscribe to individual form state at eachuseFormState
.🟢 Subscribe to form state at any component level
🔴 Increase bundle size (tree shakeable)
setError
set
shouldFocus
option is to move into the third argument for consistency purpose and more scalable for other options.🟢 APi consistency
🔴 Breaking change
unregister
add new option argument for
unregister
, it will give the user more control over how to resetformState
after an input gets removed.🟢 Better control on how
formState
react to unregister inputs🟢 User can easily unregister all inputs
🔴 Increase bundle size
Related:
#3045
#3155
touch
rename
touch
totouchedFields
, keep it consistent withdirtyFields
fromformState
.🟢 API consistency
🔴 Breaking change
Related:
#2086
deafultValues
useForm
'sdefaultValues
will shallow merged into submission results. This will affectwatch
,getValues
, andhandleSubmit
.defaultValues
will make a shallow merge with the actual form values.Note: as the lib author, I would still recommend users to include form metadata inside input hidden or custom
register
atuseEffect
, but this shallow merge update should resolve some of the simple use cases which this community demands.Poll result: https://twitter.com/HookForm/status/1356900322535370753
🟢 Convenient for simple metadata
🔴 Breaking change
Remove console warning
The ES6 module build includes references to process.env.NODE_ENV, which breaks browser usages. We will remove those
console.warning
for now, until we figure out a better solution in the long run. Also, improve the documentation to fulfill the gap.Related:
#3498
TS Improvement
We will aim to support the following API with Template literal.
watch
clearErrors
setError
🟢 Better Type guard
🔴 More restriction and potential limitation (such as type-safe max array index with being capped at 99)
warnings
from this librarywe will no longer throw a warning for incorrect usage for better ES module support.
🟢 ES Module
🔴 The user will have to refer to docs more often.
We are moving away from IE 11 at the next major version as IE11 officially ends support on the August 17th, 2021, however, you can use still V6 which has IE 11 support.
Beta Was this translation helpful? Give feedback.
All reactions