Skip to content

Instantly share code, notes, and snippets.

@bhupendra-nitt
Created April 12, 2019 05:44
Show Gist options
  • Save bhupendra-nitt/7c57e38a4a5dc14360988f739f550e8f to your computer and use it in GitHub Desktop.
Save bhupendra-nitt/7c57e38a4a5dc14360988f739f550e8f to your computer and use it in GitHub Desktop.
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