mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-04-22 06:44:18 +08:00
feat(chat-sdk/chatitem): 消息支持导出图表图片
This commit is contained in:
25
webapp/packages/chat-sdk/src/hooks/useMethodRegister.ts
Normal file
25
webapp/packages/chat-sdk/src/hooks/useMethodRegister.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useCallback, useRef } from 'react';
|
||||
|
||||
export const useMethodRegister = (fallback?: (...args: any[]) => any) => {
|
||||
const methodStore = useRef<Map<string, (...args: any[]) => any>>(new Map());
|
||||
|
||||
const register = useCallback<(key: string, method: (...args: any[]) => any) => any>(
|
||||
(key, method) => {
|
||||
methodStore.current.set(key, method);
|
||||
},
|
||||
[methodStore]
|
||||
);
|
||||
|
||||
const call = useCallback<(key: string, ...args: any[]) => any>(
|
||||
(key, ...args) => {
|
||||
const method = methodStore.current.get(key);
|
||||
if (method) {
|
||||
return method(...args);
|
||||
}
|
||||
return fallback?.(...args);
|
||||
},
|
||||
[methodStore]
|
||||
);
|
||||
|
||||
return { register, call };
|
||||
};
|
||||
Reference in New Issue
Block a user