项目作者: ogwurujohnson

项目描述 :
😎React Custom Errors, a react package for displaying custom error pages
高级语言: JavaScript
项目地址: git://github.com/ogwurujohnson/react-custom-errors.git
创建时间: 2019-07-10T14:25:15Z
项目社区:https://github.com/ogwurujohnson/react-custom-errors

开源协议:MIT License

下载


React Custom Errors

An Error Custom Display Component for React

Install

  1. npm install react-custom-errors || yarn add react-custom-errors

How to use

  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import ErrorPage from 'react-custom-errors';
  4. const App = () => (
  5. <div>
  6. <ErrorPage ></ErrorPage>
  7. </div>
  8. );
  9. export default App;

ErrorPage without props

  1. <div>
  2. <ErrorPage ></ErrorPage>
  3. </div>

In this scenerio, the component would have no error code rendered, but a very beautiful page with an svg image, signlaing an problem happened

ErrorPage with props

  1. <div>
  2. <ErrorPage code="404"></ErrorPage>
  3. </div>

In this scenerio, the component would display to the user, a beautiful error page, with the status code supplied and meaning of the status code.

If the developer wishes to customize the error message shown then, they can add an additonal prop to the ErrorPage component like this:

  1. <div>
  2. <ErrorPage code={404} customMessage="Gotcha... Page not found" link="/home" backgroundColor="brown" ></ErrorPage>
  3. </div>

Parameters

params value default value description
code number REQUIRED The error code you want displayed on the ErrorPage component
customMessage string NOT REQUIRED If provided, the package would make use of it, if not the package would generate the error message itself accurately
link string NOT REQUIRED Provide this prop, which would be a route to where the user would be directed to, if they were to click on the button to go back to dashboard
backgroundColor string NOT REQUIRED If you would love to add more feel and more color customization, to meet your sites theme, you can specify a background color as prop

More details can be found in the official site:

  • Site is still worked on

Dev Server

  1. npm run start || yarn start

Default dev server runs at localost:3000 in browser.

Run Tests

  1. npm run test:watch

Production Bundle

  1. npm run build || yarn build

Follow me on Twitter: @devopsjay