@plteam/chat-ui
Version:
CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript
17 lines (16 loc) • 616 B
JavaScript
import * as React from 'react';
export const DelayRenderer = ({ children, timeout, fallback, once }) => {
const time = timeout || 1;
const [ready, setReady] = React.useState(false);
React.useEffect(() => {
if (ready)
setReady(false);
const timeoutId = setTimeout(() => setReady(true), 50 + time);
return () => { clearTimeout(timeoutId); };
}, once ? [] : [children]);
if (!ready)
return fallback ?? null;
// eslint-disable-next-line
return (React.createElement(React.Fragment, null, children));
};
export default DelayRenderer;