@darwish/hooks-core
Version:
27 lines (26 loc) • 940 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
/**
* @description A hook to display error in development environment
* @param errorText error text
* @returns dispatchError -> Function
* @example
* const dispatchError = useDisplayDevError('error text');
* dispatchError();
* const dispatchError = useDisplayDevError();
* dispatchError('new error text');
*/
var useDisplayDevError = function (errorText) {
var _a = (0, react_1.useState)(errorText), error = _a[0], setError = _a[1];
(0, react_1.useEffect)(function () {
if (process.env.NODE_ENV === 'development' && error) {
console.error(errorText);
}
}, [error]);
var dispatchError = (0, react_1.useCallback)(function (err) {
return setError(typeof err === 'undefined' ? errorText : err);
}, []);
return dispatchError;
};
exports.default = useDisplayDevError;