Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gvergnaud/use-middleware-reducer
React.useReducer which you can use with the huge middleware ecosystem of Redux.
https://github.com/gvergnaud/use-middleware-reducer
hooks middleware react reducer redux state-management usereducer
Last synced: 16 days ago
JSON representation
React.useReducer which you can use with the huge middleware ecosystem of Redux.
- Host: GitHub
- URL: https://github.com/gvergnaud/use-middleware-reducer
- Owner: gvergnaud
- Created: 2019-06-01T11:59:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T02:27:31.000Z (almost 2 years ago)
- Last Synced: 2024-10-17T18:12:11.272Z (22 days ago)
- Topics: hooks, middleware, react, reducer, redux, state-management, usereducer
- Language: TypeScript
- Homepage: https://codesandbox.io/s/usemiddlewarereducer-example-otz3j
- Size: 828 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# useMiddlewareReducer
An efficient react hook to benefit from the huge middleware ecosystem of [Redux](https://github.com/reduxjs/redux).
With this hook, you can use **any** Redux middleware inside one of your React component, without using Redux itself!
This package exports a [Typescript](https://github.com/Microsoft/TypeScript) type defintion.
## Installation
```
npm install use-middleware-reducer
```or
```
yarn add use-middleware-reducer
```## How to use
```tsx
import useMiddlewareReducer from 'use-middleware-reducer'
import logger from 'redux-logger'const initialState = 0
const reducer = (state, action) => {
if (action.type === 'INC') return state + 1
if (action.type === 'DEC') return state - 1
}const middleware = [
logger
]export function Counter() {
const [state, dispatch] = useMiddlewareReducer(reducer, initialState, middleware)return (
<>
{state}
dispatch({ type: 'INC' })}>+
dispatch({ type: 'DEC' })}>-
>
)
}
```## See it in action
Code Sandbox demo: https://codesandbox.io/s/usemiddlewarereducer-example-otz3j