Skip to content

Commit 836b86a

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/next-15.2.4
2 parents e987f1b + bff10cf commit 836b86a

24 files changed

+761
-143
lines changed

src/components/ApiGallery.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ export default function ApiGallery() {
162162
</Link>
163163
</div>
164164
</li>
165+
<li>
166+
<div>
167+
<h3>
168+
<code>{`</>`}</code>useLens
169+
</h3>
170+
<p>
171+
Type-safe lenses for building reusable and shareable form
172+
components with precise focus on form fields.
173+
</p>
174+
<Link href="/docs/uselens" aria-label="read more about useLens">
175+
Read More ▸
176+
</Link>
177+
</div>
178+
</li>
165179
<li>
166180
<div>
167181
<h3>

src/components/Menu/MenuLinks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ export const apiLinks: Pages = [
160160
pathname: "/docs/usefieldarray",
161161
name: "useFieldArray",
162162
},
163+
{
164+
pathname: "/docs/uselens",
165+
name: "useLens",
166+
},
163167
{
164168
pathname: "/docs/createFormControl",
165169
name: "createFormControl",

src/components/sponsorsList.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
border-radius: 50px;
4949
}
5050

51+
.add {
52+
border: 1px dashed #ccc;
53+
border-radius: 50px;
54+
font-size: 12px;
55+
}
56+
5157
@media (min-width: 768px) {
5258
.logoGroup {
5359
display: grid;

src/components/sponsorsList.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function SponsorsList() {
2121
target="_blank"
2222
rel="noopener noreferrer"
2323
>
24-
<img src="/images/route4me.png" alt="route4me" />
24+
<img src="/images/route4me.png" alt="route4me"/>
2525
</a>
2626
<a
2727
href="https://www.follower24.de/"
@@ -35,15 +35,12 @@ export function SponsorsList() {
3535
/>
3636
</a>
3737
<a
38-
href="https://www.sanity.io//"
38+
href="https://opencollective.com/react-hook-form"
3939
target="_blank"
40+
className={styles.add}
4041
rel="noopener noreferrer"
4142
>
42-
<img
43-
className={styles.twicsy}
44-
src="/images/sanity.png"
45-
alt="sanity io"
46-
/>
43+
+ Sponsor
4744
</a>
4845
</div>
4946
</div>

src/content/docs/usecontroller/controller.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The following table contains information about properties which `Controller` pro
6363

6464
<TabGroup buttonLabels={["TS", "JS"]}>
6565

66-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw"
66+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw"
6767
import ReactDatePicker from "react-datepicker"
6868
import { TextField } from "@material-ui/core"
6969
import { useForm, Controller } from "react-hook-form"

src/content/docs/useform.mdx

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,10 @@ npm install @hookform/resolvers
435435
- A resolver can not be used with the built-in validators (e.g.: required, min, etc.)
436436
- When building a custom resolver:
437437
- Make sure that you return an object with both `values` and `errors` properties. Their default values should be an empty object. For example: `{}`.
438-
- The keys of the `error` object should match the `name` values of your fields.
438+
- The keys of the `errors` object should match the `name` values of your fields, but they _must_ be hierarchical rather than a single key for deep errors:
439+
`❌ { "participants.1.name": someErr }` will not set or clear properly - instead, use `✅ { participants: [null, { name: someErr } ] }` as this is reachable
440+
as `errors.participants[1].name` - you can still prepare your errors using flat keys, and then use a function like this one from the zod resolver:
441+
[toNestErrors(flatErrs, resolverOptions)](https://github.com/react-hook-form/resolvers/blob/master/src/toNestErrors.ts)
439442

440443
</Admonition>
441444

@@ -445,16 +448,11 @@ npm install @hookform/resolvers
445448

446449
<TabGroup buttonLabels={["Yup","Zod","Joi","Ajv","Vest", "Custom"]}>
447450

448-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-apply-validation-ts-forked-nmbyh"
451+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-apply-validation-ts-forked-nmbyh"
449452
import { useForm } from "react-hook-form"
450453
import { yupResolver } from "@hookform/resolvers/yup"
451454
import * as yup from "yup"
452455

453-
type Inputs = {
454-
name: string
455-
age: string
456-
}
457-
458456
const schema = yup
459457
.object()
460458
.shape({
@@ -464,7 +462,7 @@ const schema = yup
464462
.required()
465463

466464
const App = () => {
467-
const { register, handleSubmit } = useForm<Inputs>({
465+
const { register, handleSubmit } = useForm({
468466
resolver: yupResolver(schema), // yup, joi and even your own.
469467
})
470468

@@ -478,7 +476,7 @@ const App = () => {
478476
}
479477
```
480478

481-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-zod-resolver-ts-example-forked-w72vp"
479+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-zod-resolver-ts-example-forked-w72vp"
482480
import { useForm } from "react-hook-form"
483481
import { zodResolver } from "@hookform/resolvers/zod"
484482
import * as z from "zod"
@@ -491,16 +489,17 @@ const schema = z.object({
491489
type Schema = z.infer<typeof schema>
492490

493491
const App = () => {
494-
const { register, handleSubmit } = useForm<Schema>({
492+
const { register, handleSubmit } = useForm({
495493
resolver: zodResolver(schema),
496494
})
497495

498-
const onSubmit = (data: Schema) => {
499-
console.log(data)
500-
}
501-
502496
return (
503-
<form onSubmit={handleSubmit(onSubmit)}>
497+
<form
498+
onSubmit={handleSubmit((data) => {
499+
// handle inputs
500+
console.log(data)
501+
})}
502+
>
504503
<input {...register("name")} />
505504
<input {...register("age", { valueAsNumber: true })} type="number" />
506505
<input type="submit" />
@@ -509,40 +508,44 @@ const App = () => {
509508
}
510509
```
511510

512-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-joiresolver-v6-ts-forked-5pseh"
513-
import { useForm } from "react-hook-form";
514-
import { joiResolver } from "@hookform/resolvers/joi";
515-
import Joi from "joi";
511+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-joiresolver-v6-ts-forked-5pseh"
512+
import { useForm } from "react-hook-form"
513+
import { joiResolver } from "@hookform/resolvers/joi"
514+
import Joi from "joi"
516515

517516
interface IFormInput {
518-
name: string;
519-
age: number;
517+
name: string
518+
age: number
520519
}
521520

522521
const schema = Joi.object({
523522
name: Joi.string().required(),
524-
age: Joi.number().required()
525-
});
523+
age: Joi.number().required(),
524+
})
526525

527526
const App = () => {
528-
const { register, handleSubmit, formState: { errors } } = useForm<IFormInput>({
529-
resolver: joiResolver(schema)
530-
});
527+
const {
528+
register,
529+
handleSubmit,
530+
formState: { errors },
531+
} = useForm<IFormInput>({
532+
resolver: joiResolver(schema),
533+
})
531534
const onSubmit = (data: IFormInput) => {
532-
console.log(data);
533-
};
535+
console.log(data)
536+
}
534537

535538
return (
536539
<form onSubmit={handleSubmit(onSubmit)}>
537-
<input {...register("name"} />
538-
<input type="number" {...register("age"} />
540+
<input {...register("name")} />
541+
<input type="number" {...register("age")} />
539542
<input type="submit" />
540543
</form>
541-
);
544+
)
542545
}
543546
```
544547

545-
```javascript copy sandbox="https://codesandbox.io/s/react-hook-form-ajvresolver-vr3imc"
548+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-ajvresolver-vr3imc"
546549
import { useForm } from "react-hook-form"
547550
import { ajvResolver } from "@hookform/resolvers/ajv"
548551

@@ -586,7 +589,7 @@ const App = () => {
586589
}
587590
```
588591

589-
```javascript copy sandbox="https://codesandbox.io/s/vest-8q874"
592+
```tsx copy sandbox="https://codesandbox.io/s/vest-8q874"
590593
import * as React from "react"
591594
import { useForm } from "react-hook-form"
592595
import { vestResolver } from "@hookform/resolvers/vest"
@@ -633,7 +636,7 @@ const App = () => {
633636
}
634637
```
635638

636-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-customresoliver-ts-v7-juc63"
639+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-customresoliver-ts-v7-juc63"
637640
import * as React from "react"
638641
import { useForm } from "react-hook-form"
639642
import * as Joi from "joi"

src/content/docs/useform/clearerrors.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This function can manually clear errors in the form.
4343

4444
<TabGroup buttonLabels={["TS", "JS"]}>
4545

46-
```typescript sandbox="https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx"
46+
```tsx sandbox="https://codesandbox.io/s/react-hook-form-v7-ts-clearerrors-w3ymx"
4747
import * as React from "react"
4848
import { useForm } from "react-hook-form"
4949

src/content/docs/useform/control.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This object contains methods for registering components into React Hook Form.
2020

2121
<TabGroup buttonLabels={["TS", "JS"]}>
2222

23-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw"
23+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw"
2424
import { useForm, Controller } from "react-hook-form"
2525
import { TextField } from "@material-ui/core"
2626

src/content/docs/useform/getvalues.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The example below shows what to expect when you invoke `getValues` method.
4949

5050
<TabGroup buttonLabels={["TS", "JS", "Types"]}>
5151

52-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg"
52+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg"
5353
import { useForm } from "react-hook-form"
5454

5555
type FormInputs = {
@@ -107,7 +107,7 @@ export default function App() {
107107
}
108108
```
109109

110-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg"
110+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-v7-ts-getvalues-txsfg"
111111
import React from "react"
112112
import { useForm } from "react-hook-form"
113113

src/content/docs/useform/handlesubmit.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ This function will receive the form data if form validation is successful.
5454

5555
<TabGroup buttonLabels={["TS", "JS"]}>
5656

57-
```typescript copy sandbox="https://codesandbox.io/s/react-hook-form-handlesubmit-ts-v7-lcrtu"
57+
```tsx copy sandbox="https://codesandbox.io/s/react-hook-form-handlesubmit-ts-v7-lcrtu"
5858
import { useForm, SubmitHandler, SubmitErrorHandler } from "react-hook-form"
5959

6060
type FormValues = {
@@ -66,10 +66,11 @@ type FormValues = {
6666
export default function App() {
6767
const { register, handleSubmit } = useForm<FormValues>()
6868
const onSubmit: SubmitHandler<FormValues> = (data) => console.log(data)
69-
const onError: SubmitErrorHandler<FormValues> = (errors) => console.log(errors)
69+
const onError: SubmitErrorHandler<FormValues> = (errors) =>
70+
console.log(errors)
7071

7172
return (
72-
<form onSubmit={handleSubmit(onSubmit)}>
73+
<form onSubmit={handleSubmit(onSubmit, onError)}>
7374
<input {...register("firstName")} />
7475
<input {...register("lastName")} />
7576
<input type="email" {...register("email")} />

0 commit comments

Comments
 (0)