-
Notifications
You must be signed in to change notification settings - Fork 0
/
mySecondScript.html
84 lines (79 loc) · 2.39 KB
/
mySecondScript.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="babel.min.js"></script>
<script src="react.prod.min.js"></script>
<script src="react-DOM.prod.min.js"></script>
<title>Document</title>
</head>
<body>
<div id = "app"></div>
<script type="text/babel">
class AddDetails extends React.Component {
state = {
'name': null,
'rno': null,
'hometown': null
}
handleChange = (e) => {
this.setState({
[e.target.id]: e.target.value
})
}
handleSubmit = (e) => {
e.preventDefault()
this.props.addDetails(this.state)
}
render(){
return (
<div>
<form onSubmit = {this.handleSubmit}>
<label htmlFor="text">Name</label><br />
<input type="text" id='name' onChange = {this.handleChange}/><br /><br />
<label htmlFor="text">Roll Number</label><br />
<input type="text" id='rno' onChange = {this.handleChange}/><br /><br />
<label htmlFor="text">Hometown</label><br />
<input type="text" id='hometown' onChange = {this.handleChange}/><br /><br />
<button type='submit'>Submit</button>
</form>
</div>
)
}
}
class App extends React.Component {
state = {
'name': null,
'rno': null,
'hometown': null
}
addDetails = (ninja) => {
this.setState({
'name': ninja.name,
'rno': ninja.rno,
'hometown': ninja.hometown
})
}
render() {
return (
<div>
<AddDetails addDetails = {this.addDetails}/>
<XYZlamb person = {this.state}/>
</div>
)
}
}
const XYZlamb = ({person}) => {
return person.name ? (
<div>
<h2>Hello!</h2>
<h3>Name: {person.name}</h3>
<h3>Roll Number: {person.rno}</h3>
<h3>Hometown: {person.hometown}</h3>
</div>
) : null
}
ReactDOM.render(<App />, document.getElementById('app'));
</script>
</body>
</html>