Basic React example to synchronize (write) text in an HTML heading tag while typing in an input tag.
Babel + JSX HTML CSSconst 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')
);<div id="app"></div>
input {
font-size: 6vh;
}
Do not forget to set Babel on JSFiddle and add react.js and react-dom.js libraries.