44 lines
2.2 KiB
JavaScript
44 lines
2.2 KiB
JavaScript
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
|
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
|
|
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
|
|
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
|
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
|
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
|
|
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
|
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
|
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)];
|
|
} |