Skip to content

Commit f5d6786

Browse files
author
arjun-sudo
committed
form part1
1 parent d6dcc68 commit f5d6786

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

react-forms/src/App.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
4-
5-
function App() {
6-
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.js</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
22-
</div>
23-
);
24-
}
1+
import React, {Component} from "react";
2+
3+
class App extends Component{
4+
constructor() {
5+
super();
6+
this.state={
7+
firstName:"",
8+
lastName:""
9+
}
10+
this.handleChange=this.handleChange.bind(this)
11+
12+
13+
}
14+
handleChange(event){
15+
const {name,value}=event.target
16+
this.setState({
17+
[name]:value
18+
})
19+
}
20+
2521

26-
export default App;
22+
render(){
23+
return(
24+
<form>
25+
<input type="text"
26+
value={this.state.firstName}
27+
name="firstName"
28+
placeholder="First Name"
29+
onChange={this.handleChange} />
30+
<br/>
31+
32+
<input type="text"
33+
value={this.state.lastName}
34+
name="lastName"
35+
placeholder="Last Name"
36+
onChange={this.handleChange} />
37+
38+
<h1>{this.state.firstName}{this.state.lastName}</h1>
39+
</form>
40+
)
41+
}
42+
43+
44+
}
45+
export default App

0 commit comments

Comments
 (0)