Skip to content

Instantly share code, notes, and snippets.

@brettkelly
Forked from onamfc/next-issue
Created May 4, 2022 16:54
Show Gist options
  • Save brettkelly/f2ce5314140ed5234ebc52e44117c963 to your computer and use it in GitHub Desktop.
Save brettkelly/f2ce5314140ed5234ebc52e44117c963 to your computer and use it in GitHub Desktop.
import React, {useState, useEffect} from "react"
import {useRouter} from 'next/router'
const Event = ({embed}) => {
const router = useRouter()
const [embedSRC, setEmbedSRC] = useState(embed);
// useEffect(() => {
// const handleRouteChange = () => {
// setEmbedSRC(embed)
// }
// router.events.on('routeChangeStart', handleRouteChange)
// }, []);
const [isUnmounted, setIsUnmounted] = useState(false);
useEffect(() => {
setInitialSRC()
}, []);
const setInitialSRC = () => {
setEmbedSRC(embed)
}
setTimeout(() => {
console.log('booom!');
setIsUnmounted(true);
setEmbedSRC('https://app.infoweave.io/embed/uspa/ais/public/records/queryget?hierarchy_category_id=54&hierarchy_item_id=2&sub_hierarchy_item_id=8');
setTimeout(() => {
setIsUnmounted(false);
}, 200);
}, 8000);
if (isUnmounted) {
return (<div>Loading...</div>)
}
return (
<ChildComponent embedSRC={embedSRC}/>
)
}
export default Event;
const ChildComponent = (props) => {
const setURL = () => {
return {__html: `<script src=${props.embedSRC}></script>`}
}
return (
<React.Fragment>
{
<div dangerouslySetInnerHTML={setURL()}/>
}
</React.Fragment>
)
}
export async function getStaticProps() {
let embed = 'https://app.infoweave.io/embed/uspa/ais/public/records/queryget?hierarchy_category_id=54&hierarchy_item_id=2&sub_hierarchy_item_id=3';
return {
props: {
embed
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment