You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.0 KiB
30 lines
1.0 KiB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
import * as React from 'react';
|
|
import Notice from './Notice';
|
|
export default function useNotification(notificationInstance) {
|
|
var createdRef = React.useRef({});
|
|
|
|
var _React$useState = React.useState([]),
|
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
elements = _React$useState2[0],
|
|
setElements = _React$useState2[1];
|
|
|
|
function notify(noticeProps) {
|
|
notificationInstance.add(noticeProps, function (div, props) {
|
|
var key = props.key;
|
|
|
|
if (div && !createdRef.current[key]) {
|
|
var noticeEle = React.createElement(Notice, Object.assign({}, props, {
|
|
holder: div
|
|
}));
|
|
createdRef.current[key] = noticeEle;
|
|
setElements(function (originElements) {
|
|
return [].concat(_toConsumableArray(originElements), [noticeEle]);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
return [notify, React.createElement(React.Fragment, null, elements)];
|
|
} |