Download react-hook-form/examples/V6/asyncSetFormValues.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 783 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/examples/V6/asyncSetFormValues.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/examples/V6/asyncSetFormValues.tsx
-
curl -L -o asyncSetFormValues.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-hook-form/examples/V6/asyncSetFormValues.tsx
783 Bytes
| import React, { useEffect } from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import { useForm } from 'react-hook-form'; | |
| export default function App() { | |
| const { register, handleSubmit, reset } = useForm(); | |
| const onSubmit = (data) => { | |
| alert(JSON.stringify(data)); | |
| }; | |
| useEffect(() => { | |
| // you can do async server request and fill up form | |
| setTimeout(() => { | |
| reset({ | |
| firstName: 'bill', | |
| lastName: 'luo', | |
| }); | |
| }, 2000); | |
| }, [reset]); | |
| return ( | |
| <form onSubmit={handleSubmit(onSubmit)}> | |
| <h1>Async Set Form Values</h1> | |
| <label>First name</label> | |
| <input name="firstName" ref={register} /> | |
| <label>Last name</label> | |
| <input name="lastName" ref={register} /> | |
| <input type="submit" /> | |
| </form> | |
| ); | |
| } | |