An open API service indexing awesome lists of open source software.

https://github.com/dusanjovanov/use-reducer-actions

Simplified useReducer
https://github.com/dusanjovanov/use-reducer-actions

hook react use-reducer

Last synced: about 1 month ago
JSON representation

Simplified useReducer

Awesome Lists containing this project

README

        

# use-reducer-actions

Hook which simplifies `useReducer`

[![npm](https://img.shields.io/npm/v/@dusanjovanov/use-reducer-actions?color=%231E90FF&label=npm&style=for-the-badge)](https://www.npmjs.com/package/@dusanjovanov/use-reducer-actions)

```bash
npm i @dusanjovanov/use-reducer-actions
```

```bash
yarn add @dusanjovanov/use-reducer-actions
```

## Features

- Tiny `312B`
- Full Typescript support

## Usage

```tsx
import { useReducerActions } from '@dusanjovanov/use-reducer-actions';

const Counter = () => {
const [state, actions] = useReducerActions({
initialState: {
count: 0,
},
reducers: {
increment: state => {
return {
...state,
count: state.count + 1,
};
},
setCount: (state, payload: number) => {
return {
...state,
count: payload,
};
},
},
});

return (


Count: {state.count}

Increment
actions.setCount(3)}>Set count to 3

);
};
```