react-native-hooks-persist
v1.0.3
Published
React Native Hooks Persist with Async Storage
Downloads
90
Maintainers
Readme
React-Native Hooks Persist
React Native Hooks Persist with Async Storage
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
ornpm install
react-native start
react-native run-ios
orreact-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):
This project follows the all-contributors specification. Contributions of any kind welcome!