Gathering detailed insights and metrics for react-redux-hooks
Gathering detailed insights and metrics for react-redux-hooks
Gathering detailed insights and metrics for react-redux-hooks
Gathering detailed insights and metrics for react-redux-hooks
The easiest way to connect redux. Power by react hooks.
npm install react-redux-hooks
Typescript
Module System
Min. Node Version
Node Version
NPM Version
63.7
Supply Chain
93.6
Quality
74.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
50,323
Last Day
2
Last Week
5
Last Month
39
Last Year
2,770
7 Stars
29 Commits
1 Forks
1 Watchers
19 Branches
2 Contributors
Updated on Aug 24, 2022
Latest Version
0.3.0
Package Id
react-redux-hooks@0.3.0
Unpacked Size
368.17 kB
Size
99.39 kB
File Count
37
NPM Version
5.6.0
Node Version
8.11.1
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
-28.6%
5
Compared to previous week
Last Month
-69%
39
Compared to previous month
Last Year
-68%
2,770
Compared to previous year
48
The easiest way to connect redux. Power by react hooks.
npm install react-redux-hooks
or
yarn add react-redux-hooks
Just use useRedux
. It would return state
and dispatch
1import { useRedux } from 'react-redux-hooks'; 2 3const ToggleButton = () => { 4 const [state, dispatch] = useRedux(); 5 6 return ( 7 <button onClick={() => dispatch({ type: 'TOGGLE' })}> 8 {state.toggle ? 'Click to close' : 'Click to open'} 9 </button> 10 ); 11};
Just pass redux store with Provider
like react-redux
.
1import React from 'react'; 2import { createStore } from 'redux'; 3import { Provider, useRedux } from 'react-redux-hooks'; 4 5const store = createStore((state = { toggle: false }, action) => { 6 if (action.type === 'TOGGLE') { 7 return { toggle: !state.toggle }; 8 } 9 10 return state; 11}); 12 13ReactDOM.render( 14 <Provider store={store}> 15 <ToggleButton /> 16 </Provider>, 17 document.getElementById('content'), 18); 19
Just like react-redux. We combine Selector, and actions creator in react-redux-hooks
1function useRedux(mapStateToHook?, mapDispatchToHook?, options?)
useRedux accepts three different parameters, all optional. By convention, they are called:
mapStateToHook
Just like mapStateToProps.
mapStateToHook
should be defined as a function:
1function mapStateToHook(state)
Arguments
state
is the store.getState()
return valueReturn
Example:
1const mapStateToHook = (state) => state.toggle; 2 3const [toggle, dispatch] = useRedux(mapStateToHook);
mapDispatchToHook
Just like mapDispatchToProps.
mapDispatchToHook
Could defined as the three types:
undefined
would return dispatch
on hook by defaultfunction
would pass dispatch
as the function parameter for user customizeobject
would combine redux's bindActionCreators by defaultmapDispatchToHook
as the undefined
Return dispatch
on hook by default.
Example:
1const [, dispatch] = useRedux();
mapDispatchToHook
as the function
Pass dispatch
as the function parameter for user customize.
Example:
1const mapDispatchToHook = (dispatch) => dispatch({ type: 'TOGGLE' }); 2 3const [, onToggle] = useRedux(undefined, mapDispatchToHook);
mapDispatchToHook
as the object
Combine redux's bindActionCreators by default
Example:
1const onToggleAction = () => ({ type: 'TOGGLE' }); 2 3const mapDispatchToHook = { onToggle: onToggleAction }; 4 5const [, onToggle] = useRedux(undefined, mapDispatchToHook);
options
as the object
There are two options can be set:
{
pure?: boolean,
shouldHooksUpdate?: function
}
pure
: When pure
is true
, useRedux
performs several equality checks that are used to avoid unnecessary calls to change state, and ultimately to render. It uses shallowEqual to compare state/prevState. When pure
is false
, update state everytime or update state on shouldHooksUpdate
return true
.shouldHooksUpdate: (nextState, prevState) => boolean
: You could customize update function. It only works on pure
is false
.Discussion welcome to open issue
see CHANGELOG.md
git checkout -b your-new-feature-branch
git commit -am 'Add new feature'
git push origin your-new-feature-branch
master
branchPlease following angular format.
The MIT License (MIT)
Copyright (c) 2018 Lee < jessy1092@gmail.com >
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
react-tracked
State usage tracking with Proxies. Optimize re-renders for useState/useReducer, React Redux, Zustand and others.
react-hooks-redux
[English Document](README-EN.md)
hooks-proxy-store
React proxyStore hooks
react-global-state-hooks
This is a package to easily handling global-state across your react components No-redux, No-context.