redux-light-hook
v1.0.1
Published
Use hooks to build global state management
Downloads
2
Readme
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'));