-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtakingInputGitHub.rsx
79 lines (72 loc) · 1.69 KB
/
takingInputGitHub.rsx
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
const Card = (props) => {
return (
<div>
<img width="75" src={props.avatar_url} />
<div style = {{display: 'inline-block', marginLeft: 10}}>
<div style={{fontSize: '1.25em', fontWeight: 'bold'}}> Name -: {props.name}</div>
<div> Company Name -: {props.company}</div>
</div>
</div>
);
};
const CardList = (props) => {
return (
<div>
{props.cards.map(card => <Card {...card} />)}
</div>
);
}
class Form extends React.Component {
state = {userName: '' }
handleSubmit = (event) => {
event.preventDefault();
console.log('Event: Form Submit', this.state.userName)
axios.get('https://api.github.com/users/${this.state.userName}')
.then(resp => {
//Console.log(resp);
this.props.onSubmit(resp.data);
});
};
render(){
return(
<form onSubmit={this.handleSubmit}>
<input type = "text"
value={this.state.userName}
onChange={(event) => this.setState({ userName: event.target.value })}
placeholder="Github username" required/>
<button type="Submit">Add card</button>
</form>
);
}
}
class App extends React.Component {
state = {
cards: [
{
name: "Rajesh",
avatar_url: "https://avatars2.githubusercontent.com/u/7086440?v=4",
company: "Cerner"
},
{
name: "Ragnar",
avatar_url: "https://avatars2.githubusercontent.com/u/42749?v=4",
company: "Vikings"
},
]
};
addNewCard = (cardInfo) => {
//console.log(cardInfo);
this.setState(prevState => ({
cards: prevState.cards.concat(cardInfo)
}));
};
render(){
return(
<div>
<Form onSubmit={this.addNewCard}/>
<CardList cards={this.state.cards} />
</div>
);
}
}
ReactDOM.render(<App />, mountNode);