Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Created July 16, 2015 16:27
Show Gist options
  • Save bloodyowl/6e7c8bc16831d14e104c to your computer and use it in GitHub Desktop.
Save bloodyowl/6e7c8bc16831d14e104c to your computer and use it in GitHub Desktop.
// signature is (props:object, state:object, setState:function)
function App({ label }, { count = 0 }, setState) {
return (
<div>
<button
onClick={() => setState({ count: count + 1 })}>
{label + " " + count}
</button>
</div>
)
}
export default toReactClass(App)
React.render(
<App
label="clicked" />,
document.getElementById("App")
)
function toReactClass(func) {
return class extends React.Component {
state = {}
render() {
return func(this.props, this.state, ::this.setState)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment