React Iframe Smart Rerendering question
Made a base level react to ask how React handles maintaining the cursor position in iframes even though it's "rerendering" the DOM?
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://npmcdn.com/react@latest/dist/react-with-addons.js"></script>
<script src="https://npmcdn.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">
</div>
JavaScript 1.7
var Hello = React.createClass({
getInitialState: function() {
return {newState: 0};
},
triggerUpdate: function() {
console.log('trigger update');
setInterval((function() {
console.log('triggering update');
this.setState({ newState: Math.random() });
}).bind(this), 1000);
},
render: function() {
console.log('rerender trigger');
return (
<div>
<div onClick={this.triggerUpdate}>Trigger update</div>
<iframe src="https://www.w3schools.com/TAgs/tryit.asp?filename=tryhtml_textarea" width="500" height="500"></iframe>
</div>
);
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);