Gathering detailed insights and metrics for react-context-global-store
Gathering detailed insights and metrics for react-context-global-store
Gathering detailed insights and metrics for react-context-global-store
Gathering detailed insights and metrics for react-context-global-store
A simple global store based on React context
npm install react-context-global-store
Typescript
Module System
Node Version
NPM Version
TypeScript (95.94%)
JavaScript (4.06%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
22 Stars
18 Commits
2 Forks
7 Watchers
1 Branches
4 Contributors
Updated on Feb 22, 2022
Latest Version
1.1.0
Package Id
react-context-global-store@1.1.0
Unpacked Size
153.04 kB
Size
35.99 kB
File Count
167
NPM Version
5.6.0
Node Version
8.11.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
The react-context-global-store is a global state management library built on the React Context API (React version 16 or above).Using it you can build a global state repository just like redux and reference these global states in a simple way in your internal business components.It's very small (less than 300 lines after packaging) and has a clean API.
1npm install react-context-global-store
Wrap your app with the Provider component and initialize your store with createStore:
※The first level substore can only be an object, and cannot be an array or other structure. You can use other data structures in the first level substore
1// index.js
2
3import React from 'react';
4import ReactDom from 'react-dom';
5import { createStore, StoreProvider } from 'react-context-global-store';
6import App from './app';
7
8const store = createStore({
9 counter: { // The first level of the sub-store must be an object
10 val: 0,
11 pepols: [{ // The second level substore can be an array or other data structure
12 name: 'Helen',
13 age: 30,
14 }],
15 }
16});
17
18ReactDOM.render(
19 <StoreProvider store={store}>
20 <App />
21 </StoreProvider>,
22 document.getElementById('root')
23);
Then use the connect method to connect your component to the store:
1// app.js 2 3import React from 'react'; 4import { connect } from 'react-context-global-store'; 5 6class App extends React.Component { 7 8} 9 10export default connect(App, ['counter']);
Finally use this.props.store inside the component to get the defined context and update your context with setStore
Tips: Just like setState, you can pass in a callback function to get the updated context
1// before 2 3add() { 4 const { val, pepols } = this.props.store.counter; 5 pepols.push({ 6 name: 'john', 7 age: 23, 8 }) 9 this.props.setStore({ 10 counter: { 11 val: val + 1, 12 pepols, 13 } 14 }, () => { 15 console.log(this.props.store.counter.val, this.props.store.counter.pepols); // new context 16 }); 17} 18 19render() { 20 const { counter } = this.props.store; 21 return ( 22 <div> 23 {counter.val} 24 <button onClick={() => this.add()}>add</button> 25 </div> 26 ) 27} 28 29// after
React-context-global-store has some reserved words that you should not modify or use in your program, otherwise it will cause some unexpected errors.
StoreProvider Component
Container component, you need to use this component to wrap your App component when creating an application.
It receives an initialized Store so that the child component uses the connect
method to connect the component to the Store.
connect Function
Use this function to connect components to the Store
Params
setStore Function
Use this function to modify the data in the store
Params
createStore Function
Use this function to create a Store
※The first level substore can only be an object, and cannot be an array or other structure. You can use other data structures in the first level substore
Params
AdapterStore Class
Create an AdapterStore; it will be automatically stored in localized storage such as localStorage after the state updated.
You can use the injectAdapter function to customize the storage method, or use the localStorage (library comes with) storage.
Params
Example
1import { AdapterStore, createStore } from 'react-context-global-store'; 2 3const store = createStore({ 4 counter: new AdapterStore('localStorage', { 5 count: 0, 6 }) 7});
injectAdapter Function
Custom adapter, if localStorage can't meet your needs, you can customize other storage methods.
Params
Example
1import { injectAdapter, AdapterStore, createStore } from 'react-context-global-store'; 2 3injectAdapter({ 4 sessionStorage: { 5 get(key) { 6 return window.sessionStorage.getItem(key); 7 }, 8 9 set(key, val) { 10 window.sessionStorage.setItem(key, val); 11 }, 12 } 13}); 14 15const store = createStore({ 16 caches: new AdapterStore('sessionStorage', { 17 count: 0, 18 }) 19});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/12 approved changesets -- score normalized to 0
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
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-14
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 Morereact-context-hooks-store
A simple global store based on React Context and Hooks
react-global-context-store
Global state for your React app using Context api
react-context-store-global
The easiest to integrate, global state management library for React based on Context API
@impact-react/store
Reactive contexts for React