@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
26 lines (22 loc) • 678 B
text/typescript
import { PluginChannel } from '@lobehub/chat-plugin-sdk/client';
import { useEffect, useState } from 'react';
export const useOnPluginReadyForInteraction = (onReady: () => void, deps: any[] = []) => {
const [readyForRender, setReady] = useState(false);
useEffect(() => {
const fn = (e: MessageEvent) => {
if (e.data.type === PluginChannel.pluginReadyForRender) {
setReady(true);
}
};
window.addEventListener('message', fn);
return () => {
window.removeEventListener('message', fn);
};
}, []);
useEffect(() => {
if (readyForRender) {
onReady();
}
}, [readyForRender, ...deps]);
return readyForRender;
};