https://github.com/sazzadsazib/reacthookstatemanager
A simple way to manage state using react hook and context api
https://github.com/sazzadsazib/reacthookstatemanager
Last synced: 9 months ago
JSON representation
A simple way to manage state using react hook and context api
- Host: GitHub
- URL: https://github.com/sazzadsazib/reacthookstatemanager
- Owner: sazzadsazib
- License: mit
- Created: 2019-02-20T11:18:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T02:57:46.000Z (about 3 years ago)
- Last Synced: 2025-02-06T19:26:31.186Z (11 months ago)
- Language: JavaScript
- Size: 661 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Context Api Boilerplate for class and Hook
So after hook came in action was trying to mix useContext and ContextApi with Reducer to work together.
### So why I need to see this
Well `useReducer` helps you to use for only functional component not class component so if you are in any legacy project with ```class Component``` trying to use `useReducer` & `useContext` api also `context api Consumer` this repo will help you out.
I am not sure if this is right approach feel free to share your opinion.
### How this works?
for `class Component`
`import {AppContextConsumer} from './Hooks/StateManager';`
and wrap it with your component like
``AppContextConsumer(YourComponent)``
when you export the file
`state available: this.props.context` & `reducer: this.props.reducer`
For `Hook`
`import {getState} from './Hooks/StateManager';`
and use them as
` const [ state , dispatch] = getState();`
Thanks,