Skip to content

Instantly share code, notes, and snippets.

@pinyin
Last active March 30, 2018 03:34
Show Gist options
  • Save pinyin/83a6991fc0a2f1606dc2a02c5d63fbd4 to your computer and use it in GitHub Desktop.
Save pinyin/83a6991fc0a2f1606dc2a02c5d63fbd4 to your computer and use it in GitHub Desktop.
Tiny React Starter
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])
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