UNPKG

@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

37 lines (36 loc) 1.05 kB
import * as React from 'react'; export class ApiManager { apiRef; userApiRef; constructor(apiRef, userApiRef) { this.apiRef = apiRef; this.userApiRef = userApiRef; } setMethod = (name, method) => { const apiRef = this.apiRef; if (apiRef.current) { // TODO: #ANY apiRef.current[name] = method; } if (this.userApiRef?.current) { this.userApiRef.current[name] = method; } }; setPrivateMethod = (name, method) => { const apiRef = this.apiRef; if (apiRef.current) { apiRef.current[name] = method; } }; setMethods = (methods) => { for (const key in methods) { const method = methods[key]; if (method) { this.setMethod(key, method); } } }; } export const useApiManager = (apiRef, userApiRef) => { return React.useMemo(() => new ApiManager(apiRef, userApiRef), [apiRef, userApiRef]); };