What's The Best Way To Periodically Reload An Iframe With React?
I'm building a webpage using React which means I can't manipulate the DOM directly. I've tried reloading my iframe by updating the url state but that doesn't seem to reload the pag
Solution 1:
Change key property for component for example:
this.state = {iframeKey: 0};
setInterval(() =>this.setState(s => ({iframeKey: s.iframeKey + 1})), 1000);
<Iframekey={this.state.iframeKey}url={someurl}/>
Solution 2:
This is a use case for the ref
property if, as I assume, the contents of the iframe isn't under react control. Apply one to the iframe, then use the setInterval to refresh the iframe url.
The reason the iframe isn't updating when you set the URL in state is that the url hasn't changed(?) and react doesn't redraw when that's the case.
Post a Comment for "What's The Best Way To Periodically Reload An Iframe With React?"