Installations
npm install react-unistore
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.8.1
NPM Version
6.10.2
Score
65.2
Supply Chain
91.2
Quality
74.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (90.49%)
JavaScript (9.51%)
Developer
jahredhope
Download Statistics
Total Downloads
11,072
Last Day
12
Last Week
105
Last Month
658
Last Year
6,174
GitHub Statistics
9 Stars
8 Commits
1 Forks
2 Watching
2 Branches
1 Contributors
Bundle Size
1.64 kB
Minified
830.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.0.4
Package Id
react-unistore@0.0.4
Unpacked Size
26.09 kB
Size
6.74 kB
File Count
15
NPM Version
6.10.2
Node Version
12.8.1
Total Downloads
Cumulative downloads
Total Downloads
11,072
Last day
-82.1%
12
Compared to previous day
Last week
-27.6%
105
Compared to previous week
Last month
32.9%
658
Compared to previous month
Last year
251.8%
6,174
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
react-unistore
- Easy to use React Hooks
- Strong TypeScript type safety
- Redux like API
- Small footprint complements unistore nicely (350b + 778b)
unistore already has great support for connecting with React by itself. However at time of writing it does not have support for React Hooks. This package aims to provide this capability, extending the API with something close to Redux’s React Hooks API.
Install
1$ yarn add unistore react-unistore 2# OR 3$ npm install --save unistore react-unistore
API
Provider
Provider exposes a store to context. Required for all other functions to work.
Generally an entire application is wrapped in a single <Provider>
at the root.
1export default () => ( 2 <Provider value={store}> 3 <App /> 4 </Provider> 5);
useAction
Used to bind an action to the store.
1const setUsername = useAction((state, username) => ({ 2 user: { ...state.user, username }, 3}));
useSelector
Used to extract values from the store.
1const user = useSelector(state => state.user);
useStore
Used to access the store itself. Where possible use useAction
and useSelector
rather than accessing the store directly.
1const store = useStore();
connect
Pre-hooks method of connecting to the store. See unistore docs for full details.
Usage (TypeScript)
Create your State. Whilst not necessary it can be helpful to wrap useSelector
and useAction
with your State:
store.ts
1import { 2 Provider, 3 TypedUseAction, 4 TypedUseSelector, 5 useAction as _useAction, 6 useSelector as _useSelector, 7} from "react-unistore"; 8 9export interface State { 10 user: { 11 firstName?: string; 12 }; 13} 14 15export const useSelector: TypedUseSelector<State> = _useSelector; 16export const useAction: TypedUseAction<State> = _useAction; 17 18export { Provider };
client.tsx
1import { createStore, Provider } from "react-unistore"; 2 3const initialState = { 4 user: {}, 5}; 6 7const store = createStore(initialState); 8 9ReactDOM.render( 10 <Provider value={store}> 11 <App /> 12 </Provider>, 13 document.getElementById("root") 14);
ChildComponent.tsx
1import { useAction, useSelector } from "./store"; 2 3export default function ChildComponent() { 4 const user = useSelector(state => state.user); 5 const setFirstName = useAction((state, firstName: string) => ({ 6 user: { ...state, firstName }, 7 })); 8 return ( 9 <div> 10 <span>Hi {user.firstName || "you"}</span> 11 <button onClick={() => setFirstName("Fred")}>Update</button> 12 </div> 13 ); 14}
Migrating from unistore/react
If you are migrating from unistore/react to be able to use functionality available in this package you should find the API fully backwards compatiable. Simply^ change any imports from:
1import { Provider, connect } from "unistore/react";
To:
1import { Provider, connect } from "react-unistore";
^ With one exception. To align with the standard React Context API patterns the Provider must be passed as the 'value' prop.
1export default () => ( 2- <Provider store={store}> 3+ <Provider value={store}> 4 <App /> 5 </Provider> 6);
Package Size of 778 Bytes
Raw File Size (ES6 version): 3.51 KiB
Raw File Size (ES5 version): 4.00 KiB
Minified + Gzip (ES6 version): 778 Bytes
Minified + Gzip (ES5 version): 864 Bytes
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/jahredhope/react-unistore/main.yml/master?enable=pin
- Info: 0 out of 1 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
75 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-2mj8-pj3j-h362
- Warn: Project is vulnerable to: GHSA-gqf6-75v8-vr26
- Warn: Project is vulnerable to: GHSA-v45m-2wcp-gg98
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-pc5p-h8pf-mvwp
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-m6cx-g6qm-p2cx
- Warn: Project is vulnerable to: GHSA-x8qc-rrcw-4r46
- Warn: Project is vulnerable to: GHSA-4328-8hgf-7wjr
- Warn: Project is vulnerable to: GHSA-93f3-23rq-pjfp
- Warn: Project is vulnerable to: GHSA-jmqm-f2gx-4fjv
- Warn: Project is vulnerable to: GHSA-pw54-mh39-w3hc / GHSA-xgh6-85xh-479p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-r2j6-p67h-q639
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.2
/10
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-unistore
unistore
Dead simple centralized state container (store) with preact and react bindings.
@jsbit/react-unistore-router
Router used sometimes at Input Logic.
@abuffseagull/unistore
Dead simple centralized state container (store) with preact and react bindings.
@bmp/unistore
Dead simple centralized state container (store) with preact and react bindings.