Socket
Book a DemoInstallSign in
Socket

react-native-persist-state

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-persist-state

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/incleaf/react-native-persist-state/Test%20Runner?style=flat-square) ![Codecov](https://img.shields.io/codecov/c/github/incleaf/react-native-persist-state?style=flat-square) ![GitHub](

1.0.0-beta.7
latest
Source
npmnpm
Version published
Weekly downloads
15
Maintainers
1
Weekly downloads
 
Created
Source

react-native-persist-state

GitHub Workflow Status Codecov GitHub GitHub top language npm

✨ Manage persist state with simple API

  • Shared state across components using Hook
  • Ability to access state outside of components
  • Fully tested and written in TypeScript

API Overview

// 1. Create a store
const store = createPersisStore<string | null>({
  key: 'authToken',
  initialData: null,
})


// 2. Use the store inside components
function HomeScreen() {
  const [authToken, setAuthToken] = usePersistState(store)
  
  if (authToken == null) {
     return <Login onSucess={setAuthToken} />
  }
  
  return <Home />
}


// 3. Access the store outside of components
function request() {
  ... 
  if (response.statusCode === 401) {
    authTokenStore.remove()
  }
}

Installation

npm install react-native-persist-state

# Used as peer dependencies
npm install recoil react-native-async-storage/async-storage

Setting Up

// Add RecoilRoot and Suspense into your root component

import { RecoilRoot } from "recoil";
import { Suspense } from "react";

function App() {
  return (
    <RecoilRoot>
      <Suspense>
        <MyApp />
      </Suspense>
    </RecoilRoot>
  )
}

FAQs

Package last updated on 18 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.