Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mununki/hoodux

Hoodux is a helper to replace the React Redux with React hooks
https://github.com/mununki/hoodux

hooks react redux

Last synced: 21 days ago
JSON representation

Hoodux is a helper to replace the React Redux with React hooks

Awesome Lists containing this project

README

        

# Hoodux

[![npm version](https://badge.fury.io/js/hoodux.svg)](https://badge.fury.io/js/hoodux)

Hoodux is a helper to replace the React Redux with React hooks.

### [Demo](https://mattdamon108.github.io/hoodux/)

## Usage

### Install

```shell
$ npm install hoodux --save

or

$ yarn add hoodux
```

### API

1. `useHooduxProvider(reducer, initState)`

This is a hook to generate Hoodux Provider which should be placed on the top level of app. Hoodux provider will populate a state and dispatch to the app's components tree.

2. `useHoodux()`

This is a hook to pop a state and dispatch to use in any component in your app.

## Example

```js
import { useHooduxProvider, useHoodux } from "hoodux";

const initState = {
isSignedIn: false,
count: 0
};

const reducer = (state, action) => {
switch (action.type) {
case "auth":
return { isSignedIn: !state.isSignedIn };
case "changeCount":
return { count: action.payload };
default:
throw new Error("Invalid action type");
}
};

const App = () => {
const { HooduxProvider } = useHooduxProvider(reducer, initState);
return (



);
};

const Main = () => {
const { state, dispatch } = useHoodux();

return (


dispatch({ type: "auth" })}>Toggle
dispatch({ type: "changeCount", payload: 5 })}>
Change count to 5


);
};
```

## Next to do

- [ ] Add more types