UPDATE 2016-11-16 9:53am EST
It appears many people are still seeing 204 responses even though Google has claimed to have \"fixed\" the problem. Wh
Here is a react example in functional component
import React, {useEffect, useRef, useState} from "react";
type IframeGoogleDocsProps = {
url: string,
className?: string
};
export default function IframeGoogleDoc({url, className}: IframeGoogleDocsProps) {
const [iframeTimeoutId, setIframeTimeoutId] = useState(undefined);
const iframeRef = useRef(null);
useEffect(()=>{
const intervalId = setInterval(
updateIframeSrc, 1000 * 3
);
setIframeTimeoutId(intervalId)
},[]);
function iframeLoaded() {
clearInterval(iframeTimeoutId);
}
function getIframeLink() {
return `https://docs.google.com/gview?url=${url}&embedded=true`;
}
function updateIframeSrc() {
if(iframeRef.current){
iframeRef.current.src = getIframeLink();
}
}
return (
<iframe
className={className}
onLoad={iframeLoaded}
onError={updateIframeSrc}
ref={iframeRef}
src={getIframeLink()}
/>
);
}