hookstore-error
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

hookstore-error

NPM version Build Status Coverage Status NPM downloads

error handler middeware for hookstore

Install

$ npm install hookstore-error
# or 
$ yarn add hookstore-error

Usage

import { Provider, applyMiddlewares } from 'hookstore';
import errorHandler from 'hookstore-error';
 
const model = {
  name: 'foo',
  state: {},
  actions: {},
};
 
function App() {
  // App component code
}
 
function Root = () => {
  const middlewares = [
    errorHandler(),
    // add other middlewares
  ];
 
  applyMiddlewares(middlewares);
 
  return <Provider model={model}><App /></Provider>;
}
 
ReactDOM.render(<Root />, document.querySelector('app'));

Custom error handle function for yourself:

function handleError(err) {
  const { name, action, state } = this.ctx;
 
  console.error(`${name}/${action} error`, err);
}
 
const middlewares = [
  errorHandler({ error: handleError }),
  // add other middlewares
];
applyMiddlewares(middlewares);

Injoy it!

Package Sidebar

Install

npm i hookstore-error

Weekly Downloads

0

Version

0.2.2

License

MIT

Unpacked Size

8.9 kB

Total Files

7

Last publish

Collaborators

  • dmyang