UNPKG

@botonic/react

Version:

Build Chatbots using React

33 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createErrorBoundary = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); // @ts-nocheck const core_1 = require("@botonic/core"); const react_1 = tslib_1.__importStar(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