0.1.4 • Published 4 years ago

@richardo2016/use-redux-store v0.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

@richardo2016/use-redux-store

npm version downloads

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

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago