Last active
January 5, 2018 08:48
-
-
Save RyanAtViceSoftware/07b0d008f4ff8e74af46 to your computer and use it in GitHub Desktop.
Hello React - controlled components - read and write. JsFiddle: http://jsfiddle.net/gh/gist/library/pure/07b0d008f4ff8e74af46
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
div { | |
padding-right: 5px; | |
} | |
input { | |
margin: 5px; | |
} |
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
<script src="https://fb.me/react-with-addons-0.14.0.js"></script> | |
<script src="https://fb.me/react-dom-0.14.0.js"></script> | |
<div id="view"/> |
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
var ExampleForm = React.createClass({ | |
getInitialState: function() { | |
return { message: 'Read and write' } | |
}, | |
getDefaultProps: function () { | |
return { message: 'Read only' } | |
}, | |
onChange: function(event) { | |
this.setState({message: event.target.value}); | |
}, | |
render: function() { | |
return ( | |
<div> | |
<input id='readOnly' className='form-control' type='text' | |
value={this.props.message}/> | |
<input id='readAndWrite' className="form-control" type='text' | |
value={this.state.message} | |
onChange={this.onChange}/> | |
</div> | |
); | |
} | |
}); | |
ReactDOM.render( | |
<ExampleForm/>, | |
document.getElementById('view')); |
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
name: ReactJs example by Ryan Vice - www.ViceSoftware.com | |
description: Hello React - controlled components - read and write. | |
authors: | |
- Ryan Vice | |
resources: | |
- https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css | |
normalize_css: no | |
wrap: h | |
panel_js: 3 | |
panel_css: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment