react-use-redux-state
Use a Redux store.
Install
npm install --save react-use-redux-state
Usage
The hook works in a way like useState
, but for Redux.
const store = const ReduxComponent = { const state dispatch = return <p onClick= onMouseMove= dispatch > state </p> } <ReduxComponent />
ReduxComponent
would render 0 in the beginning. Its value would increase 1 after each click, increase 2 after each mouse move.
To make an in-component Redux store, use this hook along with useRef
or useMemo
.
Notice you may pass action type as method name in environments with Proxy
support. TypeScript support is also included.
Limits
Due to the flexibility of hooks, some logic like extracting component state from Redux state is designed to be left to you.
You may want to write code like:
const Component = { const store = const appState dispatch = const state =
Where StoreContext
is your context, created by something like React.createContext(store)
. Or you can just import a global store instance like the example above.
Other Solutions
License
MIT