Last active
June 8, 2017 10:10
-
-
Save prashanth1k/46a1c78c290f60a04d3d529f969b6b23 to your computer and use it in GitHub Desktop.
l1-react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Card = (props) => { | |
return ( | |
<div style={{margin:'1em'}}> | |
<img width='75' src={props.avatar_url}/> | |
<div style={{display:'inline-block', marginLeft:10}}> | |
<div style={{fontSize:'1.5em',fontWeight:'bold'}}> {props.name} </div> | |
<div> {props.company} </div> | |
</div> | |
</div> | |
); | |
} | |
var CardList=(props)=> { | |
return( | |
<div> | |
{props.cards.map(card => <Card {...card} />)} | |
</div> | |
); | |
} | |
class Form extends React.Component { | |
state = { userName: ''}; | |
handleSubmit= (event) => { | |
event.preventDefault(); | |
console.log(this.state.userName); | |
axios.get(`https://api.github.com/users/${this.state.userName}`).then((resp) => { | |
console.log(resp); | |
}); | |
}; | |
render() { | |
return ( | |
<div> | |
<form onSubmit={this.handleSubmit}> | |
<input type='text' placeholder='Github username' value={this.state.userName} | |
onChange = {(event) => this.setState({userName: event.target.value})} required /> | |
<button> Add Card </button> | |
</form> | |
</div> | |
); | |
} | |
} | |
class App extends React.Component { | |
state = { | |
cards: [ | |
{ | |
name:"Paul O’Shannessy", | |
avatar_url:'https://avatars2.githubusercontent.com/u/8445?v=3', | |
company: 'facebook' | |
}, | |
{ | |
name:"Paul O’Shannessy", | |
avatar_url:'https://avatars2.githubusercontent.com/u/8445?v=3', | |
company: 'facebook' | |
} | |
] | |
}; | |
render() { | |
return ( | |
<div> | |
<Form/> | |
<CardList cards={this.state.cards}/> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render(<App/>, mountNode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment