-
-
Save Uvacoder/6bc93252d8b59807f9f5af045b2b73a3 to your computer and use it in GitHub Desktop.
Simplest react form: useRef
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
| // using a useRef hook to manage form state with uncontrolled text area component | |
| import { useRef } from 'react'; | |
| export default function TextInputForm() { | |
| const ref = useRef(); | |
| const text = 'input'; | |
| function submitForm() { | |
| console.log(ref.current); | |
| } | |
| return ( | |
| <form onSubmit={submitForm}> | |
| <textarea id='txt' ref={ref} defaultValue={text}> | |
| {ref.current} | |
| </textarea> | |
| </form> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment