1.0.1 • Published 5 years ago

redux-light-hook v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

redux-hook

Use hooks to build global state management

npm i redux-light-hook
import React from 'react'
import ReactDOM from 'react-dom';
import useReduxHook from 'redux-light-hook';

useReduxHook.initState({
  count: 0
})

// ChangeCount.js still works
const ChangeCount = () => {
  const { setState } = useReduxHook();

  return (
    <div>
      ChangeCount组件: =>
      <button 
        onClick={() => {
          setState((state) => ({
            count: state.count+1
          }))
        }} 
      >
        +
      </button>

      <button 
        onClick={() => {
          setState((state) => ({
            count: state.count-1
          }))
        }}
      >
        -
      </button>
    </div>
  )
}

// Counter.js still works
const Counter = () => {
  const {state} = useReduxHook()

  return (
    <div>Counter: =>{state.count}</div>
  )
}

const App: React.FC = () => {

  return (
    <div className="App">
      <ChangeCount />
      <Counter/>
    </div>
  );
}

ReactDOM.render(<App />, document.getElementById('root'));