Skip to content

Commit 75eac7a

Browse files
authored
feat(useFormContext): migrate V6 to V7: register & formState errors
Added useFormContext variant to the codemod
2 parents b47852c + d4d6726 commit 75eac7a

30 files changed

+647
-187
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { formState: {
5+
errors,
6+
} } = useFormContext();
7+
8+
return (
9+
<form>
10+
<span>{errors.username.message}</span>
11+
</form>
12+
);
13+
};
14+
15+
export default Form;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { formState: {
5+
errors,
6+
} } = useFormContext();
7+
8+
return (
9+
<form>
10+
<span>{errors.username.message}</span>
11+
</form>
12+
);
13+
};
14+
15+
export default Form;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { errors } = useFormContext();
5+
6+
return (
7+
<form>
8+
<span>{errors.username.message}</span>
9+
</form>
10+
);
11+
};
12+
13+
export default Form;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { formState: {
5+
errors,
6+
} } = useFormContext();
7+
8+
return (
9+
<form>
10+
<span>{errors.username.message}</span>
11+
</form>
12+
);
13+
};
14+
15+
export default Form;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { errors: customErrors } = useFormContext();
5+
6+
return (
7+
<form>
8+
<span>{customErrors.username.message}</span>
9+
</form>
10+
);
11+
};
12+
13+
export default Form;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { formState: {
5+
errors: customErrors,
6+
} } = useFormContext();
7+
8+
return (
9+
<form>
10+
<span>{customErrors.username.message}</span>
11+
</form>
12+
);
13+
};
14+
15+
export default Form;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { errors, formState: { isDirty } } = useFormContext();
5+
6+
return (
7+
<form>
8+
<span>{errors.username.message}</span>
9+
</form>
10+
);
11+
};
12+
13+
export default Form;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const {
5+
formState: {
6+
isDirty,
7+
errors,
8+
},
9+
} = useFormContext();
10+
11+
return (
12+
<form>
13+
<span>{errors.username.message}</span>
14+
</form>
15+
);
16+
};
17+
18+
export default Form;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const { errors, formState } = useFormContext();
5+
6+
const diry = formState.isDirty;
7+
8+
return (
9+
<form>
10+
<span>{errors.username.message}</span>
11+
</form>
12+
);
13+
};
14+
15+
export default Form;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useFormContext } from 'react-hook-form';
2+
3+
const Form = () => {
4+
const {
5+
formState,
6+
} = useFormContext();
7+
8+
const {
9+
errors,
10+
} = formState;
11+
12+
const diry = formState.isDirty;
13+
14+
return (
15+
<form>
16+
<span>{errors.username.message}</span>
17+
</form>
18+
);
19+
};
20+
21+
export default Form;

0 commit comments

Comments
 (0)