UNPKG

@botonic/react

Version:

Build Chatbots using React

32 lines 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createErrorBoundary = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); // @ts-nocheck const core_1 = require("@botonic/core"); const react_1 = require("react"); const text_1 = require("../components/text"); const createErrorBoundary = ({ errorComponent = ({ errorMessage }) => ((0, jsx_runtime_1.jsx)(text_1.Text, { children: "The message cannot be displayed" })), } = {}) => { const ErrorBoundary = ({ children }) => { const [error, _setError] = (0, react_1.useState)(null); const _componentDidCatch = (error, _errorInfo) => { if ((0, core_1.isNode)()) { console.error(`Failure at:`, error); } }; const _getDerivedStateFromError = error => { return { error }; }; if (error) { return errorComponent({ errorMessage: error.message, }); } else { return children; } }; return ErrorBoundary; }; exports.createErrorBoundary = createErrorBoundary; //# sourceMappingURL=error-boundary.js.map