diff --git a/src/util/antdFeedback.js b/src/util/antdFeedback.js new file mode 100644 index 0000000..9b2cdd5 --- /dev/null +++ b/src/util/antdFeedback.js @@ -0,0 +1,24 @@ +import { message as staticMessage, notification as staticNotification } from "antd"; + +let messageApi = staticMessage; +let notificationApi = staticNotification; + +const createApiProxy = (getApi) => + new Proxy( + {}, + { + get(_target, prop) { + const api = getApi(); + const value = api[prop]; + return typeof value === "function" ? value.bind(api) : value; + } + } + ); + +export const configureAntdFeedback = ({ message, notification }) => { + if (message) messageApi = message; + if (notification) notificationApi = notification; +}; + +export const antdMessage = createApiProxy(() => messageApi); +export const antdNotification = createApiProxy(() => notificationApi);