Wondering what’s next for npm?Check out our public roadmap! »

use-enhanced-reducer
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

use-enhanced-reducer

npm version npm downloads bundle size

Simple custom hook for use React.useReducer with middlewares.

Examples

With logger middleware

import * as React from 'react';
import { useEnhancedReducer, loggerMiddleware } from 'use-enhanced-reducer';
 
const SomeComponent: React.FunctionComponent<{}> = () => {
    // see logs of actions in console
    const [state, dispatch] = useEnhancedReducer(reducer, initialState, [loggerMiddleware])
 
    // do something
}

With your custom middleware

import * as React from 'react';
import { useEnhancedReducer, TReducerMiddleware } from 'use-enhanced-reducer';
 
const customMiddleware: TReducerMiddleware = state => dispatch => action => {
    // do something
};
 
const SomeComponent: React.FunctionComponent<{}> = () => {
    const [state, dispatch] = useEnhancedReducer(reducer, initialState, [customMiddleware])
 
    // do something
}

Install

npm i use-enhanced-reducer

DownloadsWeekly Downloads

2

Version

1.0.7

License

MIT

Unpacked Size

6.33 kB

Total Files

7

Last publish

Collaborators

  • avatar