Gathering detailed insights and metrics for react-unistore
Gathering detailed insights and metrics for react-unistore
Gathering detailed insights and metrics for react-unistore
Gathering detailed insights and metrics for 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.
npm install react-unistore
Typescript
Module System
Node Version
NPM Version
TypeScript (90.49%)
JavaScript (9.51%)
Total Downloads
13,588
Last Day
1
Last Week
3
Last Month
359
Last Year
8,265
9 Stars
8 Commits
1 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Feb 13, 2021
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-95.3%
3
Compared to previous week
Last Month
-24.4%
359
Compared to previous month
Last Year
485.3%
8,265
Compared to previous year
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.
1$ yarn add unistore react-unistore 2# OR 3$ npm install --save unistore react-unistore
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.
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}
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);
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
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
81 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
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 More