@ugenc/use-storage-hook

2.0.5 • Public • Published

Simple Hook for React Native AsyncStorage

This package makes the use of Async Storage easier with React Native Project via React Hooks.

It provides you an easier way to update, remove and reach a storage key's value.

Installation

You need to have @react-native-async-storage/async-storage in your React Native project.

For AsyncStorage documentation click here.

Yarn

yarn add @ugenc/use-storage-hook

Npm

npm i @ugenc/use-storage-hook

Usage

First import the hook.

import { useStorage } from '@ugenc/use-storage-hook'

Inside your component call the hook.

import React from 'react'
import { View, Text } from 'react-native'

export default function index() {

  const [storeValue, setStore, removeStore] = useStorage('@key'); // provide a storage key.

    return (
        <View>
            <Text></Text>
        </View>
    )
}
console.log(storeValue) // value of the storage.
setStore(object) // update the storage with the new value.
removeStore() // remove all items in the storage.

Give a star :) on GitHub ugenc

Package Sidebar

Install

npm i @ugenc/use-storage-hook

Weekly Downloads

0

Version

2.0.5

License

Apache-2.0

Unpacked Size

14.5 kB

Total Files

5

Last publish

Collaborators

  • ugenc