@richardo2016/use-redux-store
Get started
npm i -S @richardo2016/use-redux-store
# or
yarn add @richardo2016/use-redux-store
Usage
import React from 'react'
import ReactDOM from 'react-dom'
import useReduxStore from '@richardo2016/use-redux-store'
const { inject, useReduxState } = useReduxStore(
// reducer
(state, action) => {
switch (action.type) {
case "increment":
return { ...state, count: state.count + 1 };
case "decrement":
return { ...state, count: state.count - 1 };
default:
return state;
}
},
// initial state
{
count: 0
}
)
const App = inject(() => {
const [{ count }, dispatch] = useReduxState();
return (
<div>
<p>count: {count}</p>
<button onClick={() => dispatch({ type: "increment" })}>+</button>
<button onClick={() => dispatch({ type: "decrement" })}>-</button>
</div>
);
})
ReactDOM.render(<App />, document.getElementById('#app'))
LICENSE
ISC
Copyright (c) 2020-present, Richard