-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtakeUserInputhalfdone.jsx
71 lines (63 loc) · 1.44 KB
/
takeUserInputhalfdone.jsx
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
const Card = (props) => {
return (
<div>
<img width="75" src={props.pic} />
<div style = {{display: 'inline-block', marginLeft: 10}}>
<div style={{fontSize: '1.25em', fontWeight: 'bold'}}> Name -: {props.Name}</div>
<div> Company Name -: {props.companyName}</div>
</div>
</div>
);
};
const CardList = (props) => {
return (
<div>
{props.cards.map(card => <Card {...card} />)}
</div>
);
}
class Form extends React.Component {
handleSubmit = (event) => {
event.preventDefault();
console.log('Event: Form Submit',this.state.userNameInput.value)
axios.get('https://api.github.com/users/${this.userNameInput.value}')
};
render(){
return(
<form onSubmit={this.handleSubmit}>
<input type = "text"
ref = {(input) => this.userNameInput = input}
placeholder = "Github username" />
<button type = "submit" > Add card </button>
</form>
);
}
}
class App extends React.Component {
state = {
cards: [
{
Name: "Rajesh",
pic: "https://avatars2.githubusercontent.com/u/7086440?v=4",
companyName: "Cerner"
},
{
Name: "Ragnar",
pic: "https://avatars2.githubusercontent.com/u/42749?v=4",
companyName: "Vikings"
},
]
};
addNewCard = (cardInfo) => {
console.log(cardInfo);
}
render(){
return(
<div>
<Form onSubmit={this.addNewCard}/>
<CardList cards = {this.state.cards} />
</div>
);
}
}
ReactDOM.render(<App />, mountNode);