Synchronize text using an Input
Basic React example to synchronize (write) text in an HTML heading tag while typing in an input tag
by Génesis García Morilla
HTML
<script src="https://unpkg.com/react@15/dist/react.min.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script>
<div id="app"></div>
CSS
input {
font-size: 6vh;
}
Babel + JSX
const Input = React.createClass({
getInitialState: function () {
return {
userInput: ''
};
},
handleUserInput: function (e) {
this.setState({
userInput: e.target.value
});
},
render: function () {
return (
<div>
<input value={this.state.userInput}
onChange={this.handleUserInput} type="text" />
<h1>{this.state.userInput}</h1>
</div>
);
}
});
ReactDOM.render(
<Input />,
document.getElementById('app')
);