components.common.Delayed.js Maven / Gradle / Ivy
import React from 'react'
import Report from '../../helpers/report'
/** A component that makes a provided component render with a delay. */
function Delayed(props) {
const [show, setShow] = React.useState(false)
const timeout = props.timeout ? props.timeout : 2000
React.useEffect(() => {
const timer = setTimeout(() => {
setShow(true);
}, timeout);
return () => clearTimeout(timer);
}, []);
if (!show)
return null
if (props.component)
return props.component
else
return Report.error(Report.frontend, Report.code.frontend.Broken, {component: "delayed"}).toNotification()
}
export default Delayed