Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-global-store

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-global-store

React Native App Store state holder and persistor

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Global Store

yarn PRsBadge npm npm

Add Global Store to your app in just One Step!

  • No Store configuration needed!
  • No Reducers or ACTIONS required.
  • Lightweight and Pure JS (TypeScript).
  • No MiddleWares needed, no more dispatch complications.
  • Very simple way to change store state, just like Component setState !
  • Simply connect your components with simpler connect wrapper
  • Easily use hooks for your functional component, useGlobalStore .
  • Inspired By redux, but distinguished from it by being faster and easier to learn and use.
Note that this lib was known before as React-Native-Redux.

Instalation

  • Install React Native Async Storage (required) if not installed.

  • Then install React Native Global Store

    npm i react-native-global-store
    

    - OR -

    yarn add react-native-global-store
    

No Linking or Pods are needed, you are ready to go!

Usage

GlobalStoreProvider

Props
initialState?:  object;
// Optional Initial State, defaults to {}

persistedKeys?:  string[];
// Optional keys to persist its values ( white list to persist )

loadingUI?:  JSX.Element;
// Optional Loading UI, defaults to : <View/>

storageKey?:  string;
// Optionally change Async Storage Key, default key is "GlobalStoreProvider"
import { GlobalStoreProvider } from "react-native-global-store"
Usage Example
import React from "react"
import { GlobalStoreProvider } from "react-native-global-store"
import AppContainer from "../navigation" // Path to Root Navigation

const myInitialState = { /* your initial state */ }

export default ()=> (
  <GlobalStoreProvider 
   initialState={myInitialState} 
   loadingUI={<MyLoadingUI />}
   persistedKeys=["user", "otherKey"] // Changes to these keys' values will be persisted.
  >
    <AppContainer />
  </GlobalStoreProvider>
)

useGlobalStore

import { useGlobalStore } from "react-native-global-store"
const [globalState, setGlobalState] = useGlobalStore()
Usage Example
import React from "react"
import { useGlobalStore } from "react-native-global-store"

const MyComponent = (props) => {

	const [globalState, setGlobalState] = useGlobalStore()
	// Then access and edit your globalState normally
	// Just like useState from React. 
	return (
		<>
			// Your Component goes here
		</>
	)
}

export default MyComponent


connect

Arguments
Componenet: ComponentClass
Usage
import React from "react"
import { connect } from "react-native-global-store"

class UserPage extend React.Component {

	// Your Component goes here
	
	// Access your store using this.props.yourKey
	// Update your store state using this.props.setGlobalState({})
}

// this will connect your global store to UserPage component props
export default connect(UserPage) 



Keywords

FAQs

Package last updated on 30 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc