are-message
Version:
This is a React global notification message component. It is a standalone implementation of the are-visual message component.
41 lines (34 loc) • 935 B
JavaScript
import React from 'react';
import ReactDOM from 'react-dom';
import MessageContainer from '../container';
import createContainer from './create-container';
var instance = null;
/**
* 渲染 Message 容器
*/
function render(callback) {
var called = false;
var handleRef = function handleRef(value) {
if (called) {
return;
}
called = true;
callback === null || callback === void 0 ? void 0 : callback(value);
};
ReactDOM.render( /*#__PURE__*/React.createElement(MessageContainer, {
ref: handleRef
}), createContainer());
}
/**
* 获取实例
*/
export default function createInstance(callback) {
if (instance !== null && instance !== undefined) {
callback === null || callback === void 0 ? void 0 : callback(instance);
return;
}
render(function (msgInstance) {
instance = msgInstance;
callback === null || callback === void 0 ? void 0 : callback(msgInstance);
});
}