Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
Forked from RyanAtViceSoftware/fiddle.html
Last active August 30, 2015 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalicarus/012bdcfbbe8bacdd622c to your computer and use it in GitHub Desktop.
Save digitalicarus/012bdcfbbe8bacdd622c to your computer and use it in GitHub Desktop.
Hello React - composite components - how to componse simple components. JsFiddle: http://jsfiddle.net/gh/gist/library/pure/27ec782a76990860929b/
<!-- Required for using JSX in JsFiddle -->
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>
<div id="view"/>
var HelloMessage = React.createClass({
render: function() {
return <div>{this.props.message}</div>;
}
});
var HelloReact = React.createClass({
getInitialState: function() {
return { message: 'default'}
},
updateMessage: function () {
console.info('updateMessage');
this.setState({
message: React.findDOMNode(this.refs.messageTextBox).value});
},
render: function() {
return (
<div>
<HelloMessage message='Hello React'></HelloMessage>
<input type='text' ref='messageTextBox' />
<button onClick={this.updateMessage}>Update</button>
<div>{this.state.message}</div>
</div>
);
}
});
React.render(
<HelloReact/>,
document.getElementById('view'));
name: ReactJs example by Ryan Vice - www.ViceSoftware.com
description: Hello React - composite components - how to componse simple components.
authors:
- Ryan Vice
resources:
- http://fb.me/react-0.13.1.js
- http://fb.me/JSXTransformer-0.13.1.js
normalize_css: no
wrap: h
panel_js: 2
panel_css: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment