Created
April 12, 2019 05:44
-
-
Save bhupendra-nitt/7c57e38a4a5dc14360988f739f550e8f to your computer and use it in GitHub Desktop.
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'; | |
const App = () => { | |
const [name, setName ] = useState('') | |
const [age, setAge] = useState('') | |
const [error, validateForm] = useState({}) | |
const handleSubmit = () => { | |
if(!age || !name) { | |
validateForm({message: 'Enter all values'}) | |
} else { | |
validateForm({}) | |
} | |
} | |
return ( | |
<div> | |
<div>Name: {name}</div> | |
<div>Age: {age}</div> | |
<input value={name} onChange={(e) => setName(e.target.value)}/> | |
<input value={age} onChange={(e) => setAge(e.target.value)}/> | |
<button onClick={handleSubmit}>Submit</button> | |
<div style={{color: 'red' }}> | |
{error.message} | |
</div> | |
</div> | |
); | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment