Last active
October 18, 2021 13:04
-
-
Save chadmuro/d8b596e9cbbc328dbe65f650298b9eb6 to your computer and use it in GitHub Desktop.
Uncontrolled Component
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 React, { useRef } from "react"; | |
const Uncontrolled = () => { | |
const inputRef = useRef(null); | |
const handleSubmit = (e) => { | |
e.preventDefault(); | |
console.log(inputRef.current.value); | |
}; | |
return ( | |
<form> | |
<input type="text" ref={inputRef} /> | |
<button onClick={handleSubmit}>Submit</button> | |
</form> | |
); | |
}; | |
export default Uncontrolled; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment