This file contains 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
// 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) |
This file contains 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
React.render( | |
<App | |
label="clicked" />, | |
document.getElementById("App") | |
) |
This file contains 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
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