phx-react
Version:
PHX REACT
35 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useShowNotification = exports.DEFAULT_ALERT_STATE = void 0;
const react_1 = require("react");
exports.DEFAULT_ALERT_STATE = {
message: '',
isFailure: false,
show: false,
type: 'add',
};
const useShowNotification = () => {
const [notification, setNotification] = (0, react_1.useState)(exports.DEFAULT_ALERT_STATE);
const onShowNotification = (data) => {
setNotification((prev) => ({ ...prev, ...data }));
};
const onHideNotification = () => {
setNotification(exports.DEFAULT_ALERT_STATE);
};
(0, react_1.useEffect)(() => {
if (notification.show) {
const timerId = setTimeout(() => {
setNotification((pre) => ({ ...pre, show: false, isFailure: false }));
}, 5000);
return () => clearTimeout(timerId);
}
return;
}, [notification.show]);
return {
notification,
onShowNotification,
onHideNotification,
};
};
exports.useShowNotification = useShowNotification;
//# sourceMappingURL=use-show-notification.js.map