-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example useWatch and re-export react-hook-form API
- Loading branch information
Showing
4 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {FunctionComponent, PropsWithChildren} from "react"; | ||
import {AppBar, Box, Button, Toolbar} from "@mui/material"; | ||
import Link from "next/link"; | ||
|
||
export const Layout: FunctionComponent<PropsWithChildren> = ({children}) => { | ||
return ( | ||
<Box> | ||
<AppBar> | ||
<Toolbar> | ||
<Link href={'/'} passHref> | ||
<Button color={'inherit'}> | ||
Base | ||
</Button> | ||
</Link> | ||
<Link href={'/withSub'} passHref> | ||
<Button color={'inherit'}> | ||
With useWatch | ||
</Button> | ||
</Link> | ||
</Toolbar> | ||
</AppBar> | ||
<Toolbar/> | ||
<Box padding={3}> | ||
|
||
{children} | ||
</Box> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {Button} from "@mui/material"; | ||
import {FormContainer, TextFieldElement, useWatch} from "react-hook-form-mui"; | ||
|
||
const SubComponent = () => { | ||
const [name, email] = useWatch({ | ||
name: ["name", "email"] | ||
}); | ||
console.log(name, email); | ||
return ( | ||
<> | ||
<Button type={"submit"} color={"primary"} disabled={!(name && email)}> | ||
Submit | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export default function IndexPage() { | ||
|
||
return ( | ||
<div> | ||
<FormContainer | ||
defaultValues={{ | ||
name: "" | ||
}} | ||
onSuccess={(data) => { | ||
console.log(data) | ||
}} | ||
> | ||
<TextFieldElement name={"name"} label={"Name"} required/> <br/> | ||
<TextFieldElement | ||
name={"email"} | ||
label={"Email"} | ||
required | ||
type={"email"} | ||
/>{" "} | ||
<br/> | ||
<TextFieldElement name={"interest"} label={"Interest"}/> <br/> | ||
<SubComponent/> | ||
</FormContainer> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters