Skip to content

Latest commit

 

History

History
116 lines (70 loc) · 2.91 KB

README.md

File metadata and controls

116 lines (70 loc) · 2.91 KB

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!