Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mununki/hoodux
- Owner: mununki
- License: mit
- Created: 2019-06-09T16:17:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T18:36:29.000Z (about 2 years ago)
- Last Synced: 2024-08-22T15:25:18.389Z (5 months ago)
- Topics: hooks, react, redux
- Language: JavaScript
- Size: 2.31 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 --saveor
$ 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