Last active
October 18, 2016 04:33
-
-
Save sstur/748c1e48e8374e8ab1f2bddc4270b83f to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import './App.css'; | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
error: null, | |
data: null, | |
}; | |
fetch('https://api.github.com/repos/facebook/react') | |
.then((response) => response.json()) | |
.then((data) => { | |
this.setState({data: data}); | |
}) | |
.catch((error) => { | |
this.setState({error: error}); | |
}); | |
} | |
render() { | |
let {data, error} = this.state; | |
if (error != null) { | |
return <p>We received an error: {error.message}</p>; | |
} | |
if (data == null) { | |
return <p>Still waiting...</p>; | |
} | |
return ( | |
<div> | |
<p>This repository has {data.stargazers_count} stars!</p> | |
</div> | |
); | |
} | |
} | |
export default App; |
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
import React from 'react'; | |
import CounterButton from './CounterButton'; | |
import './App.css'; | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
count: 0 | |
}; | |
} | |
render() { | |
let count = this.state.count; | |
let inc = () => { | |
this.setState({count: count + 1}); | |
} | |
return ( | |
<div> | |
<p>Your count is {count}</p> | |
<CounterButton onClick={inc} count={count} /> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment