Created
July 8, 2024 06:53
-
-
Save sprobejames/1188f1b7705c3cf30d99ab530849fe55 to your computer and use it in GitHub Desktop.
React Datepicker, MUI, RHF See https://stackoverflow.com/a/67995336
This file contains hidden or 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
| import { Controller, useForm } from 'react-hook-form' | |
| import DatePicker from 'react-datepicker' | |
| const App = () => { | |
| const { control, register, handleSubmit } = useForm(); | |
| const onSubmit = (data) => { | |
| alert(JSON.stringify(data)); | |
| }; | |
| return ( | |
| <form onSubmit={handleSubmit(onSubmit)}> | |
| <Controller | |
| control={control} | |
| name='date-input' | |
| render={({ field }) => ( | |
| <DatePicker | |
| placeholderText='Select date' | |
| onChange={(date) => field.onChange(date)} | |
| selected={field.value} | |
| /> | |
| )} | |
| /> | |
| <button type="submit">Submit</button> | |
| </form> | |
| ) | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment