用于捕捉react组件错误
npm install @kne/react-error-boundary``shell script`
npm i @kne/react-error-boundary
`jsx
import ErrorBoundary from '@kne/react-error-boundary';
const ErrorComponent = ({error})=>{
console.error(error);
return
const SomeComponent = ()=>{
return
};
const SomeComponent2 = ()=>{
return
console.error(error);
return 组件发生错误
}}>
};
``
|属性名|说明|类型|默认值|
| --- | --- | --- | --- |
|errorComponent|当子组件发生错误的时候渲染该组件,并传入属性error|Component|- |
|errorRender|当子组件发生错误的时候执行该方法,并传入参数error,需要返回jsx,注意:当errorComponent存在时该方法会被忽略|func|- |
|onError|当子组件发生错误的时候执行该方法|func|- |