@orca-fe/pocket
Version:
UI components by orca-team
51 lines • 3.72 kB
JavaScript
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/* eslint-disable prefer-template,@typescript-eslint/restrict-plus-operands */
import React, { useState } from 'react';
import { ErrorCatcher } from "../..";
import { Button } from 'antd';
import 'antd/es/button/style';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var ComponentWithError = () => {
var _useState = useState(Math.random() * 10),
_useState2 = _slicedToArray(_useState, 2),
num = _useState2[0],
setNum = _useState2[1];
return /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("span", {
children: num.toFixed(2)
}), /*#__PURE__*/_jsx(Button, {
onClick: () => {
var number = num - Math.random() * 3;
// 错误地将 num 改为了 string 类型,导致渲染报错
// @ts-expect-error
setNum(number > '0' ? number : '0');
},
children: "Click me"
})]
});
};
var Demo = () => /*#__PURE__*/_jsxs("div", {
children: [/*#__PURE__*/_jsx("p", {
children: "ErrorCatcher \u80FD\u591F\u62E6\u622A\u5185\u90E8\u5143\u7D20\u5728\u6E32\u67D3\u65F6\u51FA\u73B0\u7684\u5F02\u5E38"
}), /*#__PURE__*/_jsx("p", {
children: "\u4E0B\u9762\u7684\u7EC4\u4EF6\uFF0C\u70B9\u51FB\u6309\u94AE\u540E\uFF0C\u53EF\u80FD\u4F1A\u9519\u8BEF\u5730\u5C06 number \u8BBE\u7F6E\u4E3A string\uFF0C\u5BFC\u81F4\u6E32\u67D3\u5F02\u5E38"
}), /*#__PURE__*/_jsx(ErrorCatcher, {
errorTips: "\u54CE\u5440\uFF0C\u8FD9\u91CC\u51FA\u73B0\u4E86\u4E00\u70B9\u95EE\u9898",
children: /*#__PURE__*/_jsx(ComponentWithError, {})
}), /*#__PURE__*/_jsx(ErrorCatcher, {
errorTips: "\u54CE\u5440\uFF0C\u8FD9\u91CC\u51FA\u73B0\u4E86\u4E00\u70B9\u95EE\u9898",
children: /*#__PURE__*/_jsx(ComponentWithError, {})
}), /*#__PURE__*/_jsx(ErrorCatcher, {
errorTips: "\u54CE\u5440\uFF0C\u8FD9\u91CC\u51FA\u73B0\u4E86\u4E00\u70B9\u95EE\u9898",
children: /*#__PURE__*/_jsx(ComponentWithError, {})
}), /*#__PURE__*/_jsx("p", {
children: "\u4E0B\u9762\u8FD9\u4E2A\u7EC4\u4EF6\uFF0C\u672A\u88AB\u5305\u88F9\uFF0C\u62A5\u9519\u5C06\u5BFC\u81F4\u767D\u5C4F"
}), /*#__PURE__*/_jsx(ComponentWithError, {})]
});
export default Demo;