@richardo2016/use-redux-store
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @richardo2016/use-redux-store

Weekly Downloads

0

Version

0.1.4

License

ISC

Unpacked Size

6.32 kB

Total Files

8

Last publish

Collaborators

  • richardo2016