Skip to content
React Native Hooks Persist with Async Storage
JavaScript Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo
.all-contributorsrc
.prettierrc.json
LICENSE
README.md
index.d.ts
index.js
package.json
react-native-hooks-persist.podspec

README.md

React-Native Hooks Persist

React Native Hooks Persist with Async Storage

language

All Contributors

NPM

GitHub issues

GitHub stars

Getting Started

Install

yarn add react-native-hooks-persist

or

npm install react-native-hooks-persist

Methods

Name Description
useStatePersist Main hook persist method
removeStatePersist Remove an item from Store
debugStatePersist Debug all items on Store

Basic usage

imports

import {
  useStatePersist,
  removeStatePersist,
  debugStatePersist,
} from 'react-native-hooks-persist';

const DB_NAME = 'globalStorage';
const FIELD_KEY = 'selectedColor';
const INITIAL_VALUE = 'Red';

Create

const [color, setColor] = useStatePersist(DB_NAME, FIELD_KEY, INITIAL_VALUE);

Read

<Text>{color.selectedColor} Selected</Text>

Update

setColor(DB_NAME, FIELD_KEY, 'Blue');

Update with an Object (MultiSet)

setValue(DB_NAME, { [FIELD_KEY]: 4, [FIELD_KEY_COLOR]: 'Black' });

Delete

removeStatePersist(DB_NAME, FIELD_KEY);

Debug all Items

debugStatePersist(DB_NAME);

Example in /demo

Run in demo folder:

  • yarn or npm install

  • react-native start

  • react-native run-ios or react-native run-android

Contributing

  • Clone this Repo
  • Install dependencies
  • Checkout develop branch
  • Add your feature or fix
  • Make sure your improvement works
  • Open a pull request

Baked with Love ♥ from Cologne & Huelva

Contributors

Thanks goes to these wonderful people (emoji key):

Yaxian
Yaxian

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

You can’t perform that action at this time.