Created
October 18, 2021 13:05
-
-
Save chadmuro/e51ad22b212b6f763c0632f4392b9039 to your computer and use it in GitHub Desktop.
Controlled 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, { useState } from "react"; | |
const Controlled = () => { | |
const [inputText, setInputText] = useState(""); | |
const handleSubmit = (e) => { | |
e.preventDefault(); | |
console.log(inputText); | |
}; | |
return ( | |
<form> | |
<input | |
type="text" | |
value={inputText} | |
onChange={(e) => setInputText(e.target.value)} | |
/> | |
<button onClick={handleSubmit}>Submit</button> | |
</form> | |
); | |
}; | |
export default Controlled; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment