App.js :
import './App.css';
import FormData from './form'
function App() {
return (
<div className="App">
<FormData />
</div>
);
}
export default App;
Form.js :
import { useState } from "react"
const FormData = () => {
const[name, setName] = useState("")
const[fullname, setFullName] = useState("")
const inputEvent = (e) => {
setName(e.target.value)
}
const formSubmit = (e) => {
e.preventDefault()
setFullName(name)
}
return (
<>
<h1> Form {fullname} </h1>
<form onSubmit= {formSubmit}>
<label>Enter name</label>
<input type="text" id="name" value ={name} onChange= {inputEvent} />
<button type="submit">Submit</button>
</form>
</>
)
}
export default FormData
0 Comments