-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding stories for react-hook-form usage
- Loading branch information
1 parent
3b8b47f
commit 41e650e
Showing
5 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,41 @@ | ||
import { Button, Stack } from '@mui/material'; | ||
import { ReactNode } from 'react'; | ||
import { Control, FieldErrors, SubmitHandler, useForm } from 'react-hook-form'; | ||
|
||
interface FormValues { | ||
basic: string; | ||
ccExpire: string; | ||
ccNum: string; | ||
currency: string; | ||
currencyRtl: string; | ||
pct: string; | ||
phone: string; | ||
ssn: string; | ||
zip: string; | ||
} | ||
|
||
export function ReactHookFormDemo({ | ||
children, | ||
}: { | ||
// eslint-disable-next-line | ||
children: (vals: { control: Control<FormValues, any>; errors: FieldErrors<FormValues> }) => ReactNode; | ||
}) { | ||
const { | ||
control, | ||
formState: { errors }, | ||
handleSubmit, | ||
} = useForm<FormValues>({ defaultValues: { currency: '', currencyRtl: '0', phone: '' } }); | ||
|
||
const onSubmit: SubmitHandler<FormValues> = (data) => console.log('submitted', data); | ||
|
||
return ( | ||
<form noValidate onSubmit={handleSubmit(onSubmit)}> | ||
<Stack spacing={2}> | ||
{children({ control, errors })} | ||
<Button type="submit" variant="outlined"> | ||
Submit | ||
</Button> | ||
</Stack> | ||
</form> | ||
); | ||
} |