UNPKG

rsuite

Version:

A suite of react components

34 lines (30 loc) 1.23 kB
import toaster from './toaster'; import { useCustom } from '../utils'; /** * Hook to use the toaster * @returns toaster { push, remove, clear } */ var useToaster = function useToaster() { var _useCustom = useCustom(), toasters = _useCustom.toasters; return { push: function push(message, options) { var _toasters$current; var customToaster = toasters === null || toasters === void 0 ? void 0 : (_toasters$current = toasters.current) === null || _toasters$current === void 0 ? void 0 : _toasters$current.get((options === null || options === void 0 ? void 0 : options.placement) || 'topCenter'); return customToaster ? customToaster.push(message) : toaster.push(message, options); }, remove: function remove(key) { toasters ? Array.from(toasters.current).forEach(function (_ref) { var c = _ref[1]; return c === null || c === void 0 ? void 0 : c.remove(key); }) : toaster.remove(key); }, clear: function clear() { toasters ? Array.from(toasters.current).forEach(function (_ref2) { var c = _ref2[1]; return c === null || c === void 0 ? void 0 : c.clear(); }) : toaster.clear(); } }; }; export default useToaster;