Last active
March 30, 2018 03:34
-
-
Save pinyin/83a6991fc0a2f1606dc2a02c5d63fbd4 to your computer and use it in GitHub Desktop.
Tiny React Starter
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
import * as ReactDOM from 'react-dom' | |
import * as React from 'react' | |
export class Component extends React.Component { | |
render() { | |
return <div style={{cursor: 'pointer', userSelect: 'none'}} | |
onClick={()=> this.clicked()}> | |
This text is clicked {this.state.count} times. | |
</div> | |
} | |
constructor(props) { | |
super(props) | |
this.state = {count: 0} | |
} | |
clicked(){ | |
this.setState({count: this.state.count + 1}) | |
} | |
} | |
ReactDOM.render(<Component/>, document.body.children[0]) |
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
const {execSync} = require('child_process') | |
const {existsSync, writeFileSync} = require('fs') | |
writeFileSync("package.json", `{ "name": "hello-react" }`) | |
writeFileSync("index.html", `<html><body><div/><script src="Component.jsx"></script></body></html>`) | |
if(!existsSync(`./node_modules/parcel-bundler`)) | |
execSync(`npm install parcel-bundler --save`, {stdio: 'inherit'}) | |
execSync(`npx parcel --open --no-cache index.html`, {stdio: 'inherit'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment