Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-native-global-store
Advanced tools
connect
wrapperuseGlobalStore
.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!
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"
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>
)
import { useGlobalStore } from "react-native-global-store"
const [globalState, setGlobalState] = useGlobalStore()
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
Componenet: ComponentClass
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)
FAQs
React Native App Store state holder and persistor
We found that react-native-global-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.