Skip to content

Instantly share code, notes, and snippets.

@rava-dosa
Created September 29, 2018 10:31
Show Gist options
  • Save rava-dosa/c622bb9fdf644c5b09d43219b69a1210 to your computer and use it in GitHub Desktop.
Save rava-dosa/c622bb9fdf644c5b09d43219b69a1210 to your computer and use it in GitHub Desktop.
basic react with jsx working
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<!-- Don't use this in production: -->
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class App extends React.Component {
constructor(props){
super(props);
this.state = {
repos: []
}
}
componentDidMount() {
fetch('http://localhost:8080')
.then(response => response.json())
.then(json => {
console.log(json)
this.setState({repos: json})
})
}
render() {
return (
<div>
<h3>Hello</h3>
{this.state.repos.map((repo, i) => {
return <h4 key={i}>{repo}</h4>
})}
</div>
)
}
}
ReactDOM.render(<App/>,document.getElementById('root'));
</script>
<!--
Note: this page is a great way to try React but it's not suitable for production.
It slowly compiles JSX with Babel in the browser and uses a large development build of React.
Read this section for a production-ready setup with JSX:
http://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project
In a larger project, you can use an integrated toolchain that includes JSX instead:
http://reactjs.org/docs/create-a-new-react-app.html
You can also use React without JSX, in which case you can remove Babel:
https://reactjs.org/docs/react-without-jsx.html
-->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment