Skip to content

Instantly share code, notes, and snippets.

@asci
Created October 29, 2018 09:42
Show Gist options
  • Save asci/5f1afb9a772392adf318c624deac9a7a to your computer and use it in GitHub Desktop.
Save asci/5f1afb9a772392adf318c624deac9a7a to your computer and use it in GitHub Desktop.
Iframe React issue
// Could be served via CRA with default port 3000
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
constructor(props) {
super(props);
this.state = { num: 0 };
}
componentDidMount() {
setInterval(() => {
this.setState({ num: this.state.num + 1 });
}, 1000);
}
render() {
return (
<div className="App">
<h1>To trigger updates {this.state.num}</h1>
<iframe
width="300"
height="200"
src="http://localhost:8000/index.html"
/>
</div>
);
}
}
const rootElement = document.getElementById('root');
ReactDOM.render(<App />, rootElement);
<!-- SHOULD BE SERVED FROM DIFFERENT LOCATION\PORT -->
<!-- eg. http://localhost:8000 I used `python -m SimpleHTTPServer 8000 .` -->
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<textarea>This</textarea>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment