Skip to content

Commit

Permalink
fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Jan 20, 2025
1 parent 2b6dbc7 commit 28f4d2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pnpm-lock.yaml
pnpm-lock.yaml
.cache/
.contentlayer/
.next/
43 changes: 21 additions & 22 deletions src/content/docs/useform/setvalue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,32 @@ const App = () => {
**Dependant Fields**

```typescript sandbox="https://codesandbox.io/s/dependant-field-dwin1"
import * as React from "react";
import { useForm } from "react-hook-form";
import * as React from "react"
import { useForm } from "react-hook-form"

type FormValues = {
a: string;
b: string;
c: string;
};
a: string
b: string
c: string
}

export default function App() {
const { watch, register, handleSubmit, setValue, formState } = useForm<
FormValues
>({
defaultValues: {
a: "",
b: "",
c: ""
}
});
const onSubmit = (data: FormValues) => console.log(data);
const [a, b] = watch(["a", "b"]);
const { watch, register, handleSubmit, setValue, formState } =
useForm<FormValues>({
defaultValues: {
a: "",
b: "",
c: "",
},
})
const onSubmit = (data: FormValues) => console.log(data)
const [a, b] = watch(["a", "b"])

React.useEffect(() => {
if (formState.touchedFields.a && formState.touchedFields.b && a && b) {
setValue("c", `${a} ${b}`);
setValue("c", `${a} ${b}`)
}
}, [setValue, a, b, formState]);
}, [setValue, a, b, formState])

return (
<form onSubmit={handleSubmit(onSubmit)}>
Expand All @@ -159,14 +158,14 @@ export default function App() {
<button
type="button"
onClick={() => {
setValue("a", "what", { shouldTouch: true });
setValue("b", "ever", { shouldTouch: true });
setValue("a", "what", { shouldTouch: true })
setValue("b", "ever", { shouldTouch: true })
}}
>
trigger value
</button>
</form>
);
)
}
```

Expand Down

0 comments on commit 28f4d2f

Please sign in to comment.