Created
March 22, 2016 21:53
-
-
Save paulohp/e77109e8495c8b5bf447 to your computer and use it in GitHub Desktop.
paulo's react-starter-kit
This file contains hidden or 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
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = { | |
items: [] | |
} | |
} | |
componentDidMount() { | |
fetch('/api/items') | |
.then(req => req.json()) | |
.then((json) => { | |
this.setState({ | |
items: json | |
}) | |
}) | |
} | |
render() { | |
return ( | |
<div> | |
{this.state.items.map((item,i) => { | |
<span key={i}>{item.name}</span> | |
})} | |
</div> | |
) | |
} | |
} | |
ReactDOM.render( | |
<App />, | |
document.getElementById('root') | |
) |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>App</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/0.11.0/fetch.min.js"></script> | |
</head> | |
<body> | |
<main id="root"></section> | |
<script type="text/babel" src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment