@chainlit/react-client 包提供了一组 React hooks 和一个 API 客户端,用于从任何 React 应用程序连接到您的 Chainlit 应用程序。该包包含用于管理聊天会话、消息、数据和交互的 hooks。
@chainlit/react-client
要在您的项目目录中安装此包,请运行以下命令
npm install @chainlit/react-client
此包使用 Recoil 管理其状态。这意味着您必须将您的应用程序包裹在 Recoil provider 中
import React from 'react'; import ReactDOM from 'react-dom/client'; import { RecoilRoot } from 'recoil'; import { ChainlitAPI, ChainlitContext } from '@chainlit/react-client'; const CHAINLIT_SERVER_URL = 'http://localhost:8000'; const apiClient = new ChainlitAPI(CHAINLIT_SERVER_URL, 'webapp'); ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( <React.StrictMode> <ChainlitContext.Provider value={apiClient}> <RecoilRoot> <MyApp /> </RecoilRoot> </ChainlitContext.Provider> </React.StrictMode> );
此页面有帮助吗?