Skip to content

Instantly share code, notes, and snippets.

@RyanAtViceSoftware
Last active January 5, 2018 08:48
Show Gist options
  • Save RyanAtViceSoftware/07b0d008f4ff8e74af46 to your computer and use it in GitHub Desktop.
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
div {
padding-right: 5px;
}
input {
margin: 5px;
}
<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"/>
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'));
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