Created
September 22, 2019 06:15
-
-
Save zeuslawyer/d1a1e11dcc1ca85c3f87e20403eac675 to your computer and use it in GitHub Desktop.
react hooks based controlled form
This file contains 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"; | |
import ReactDOM from "react-dom"; | |
import "./styles.css"; | |
function App() { | |
const defaultFormState = { | |
first: '', | |
second: '', | |
third: '', | |
fourth: '' | |
} | |
const [inputs, setInputs] = useState(defaultFormState) | |
return ( | |
<div className="App"> | |
<h1>Hello CodeSandbox</h1> | |
<h2>Start editing to see some magic happen!</h2> | |
<input name="first" value ={inputs.first} onChange= {(e)=>setInputs({...inputs, [e.target.name]: e.target.value})} /> | |
<input name="second" value = {inputs.second} onChange= {(e)=>setInputs({...inputs, [e.target.name]: e.target.value})} /> | |
<input name="third" value = {inputs.third} onChange= {(e)=>setInputs({...inputs, [e.target.name]: e.target.value})} /> | |
<input name="fourth" value = {inputs.fourth} onChange= {(e)=>setInputs({...inputs, [e.target.name]: e.target.value})} /> | |
</div> | |
); | |
} | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<App />, rootElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment