npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-local-storage

v1.5.2

Published

Basic AsyncStorage wrapper for React Native to reduce code clutter

Downloads

36

Readme

react-native-local-storage

Simple AsyncStorage wrapper for React Native to solve code mess

How to install

npm i react-native-local-storage --save

Why did I build this?

While working on a React Native project, I discovered that AsyncStorage and its async nature was a pain in the bottom. It was also very troublesome to copy the same chunk of code everywhere when we needed to access the storage. Thus, I decided to create a package to solve some of my problems and hopefully someone else's too!

Methods

All methods are Promise-based.

  • get(keyName) : Get key(s) from local storage. keyname may be a string or an array.
  • set(keyName, value) : Save value(s) to keyname(s). keyname and value may be a string or an array (both must be the same type).
  • getSet(keyName, callback) : Get a key from local storage and execute callback with the data. callback receives the key and value.
  • getAllKeys() : Get all keys from local storage.
  • merge(keyName, value) : merge value to existing keyname value. keyname and value may be a string or an array (both must be the same type).
  • remove(keyName) : Remove key(s) from local storage. keyname may be a string or an array.
  • clear() : Remove all keys from local storage.

Examples

// Save to a key, then immediately fetch it.
var ls = require('react-native-local-storage');

ls.save('name', 'Kobe Bryant')
  .then(() => {
    ls.get('name').then((data) => {console.log("get: ", data)});
    // output should be "get: Kobe Bryant"
  })

getSet : Auto setState feature

Sometimes, it's very annoying to setState separately after grabbing the data from AsyncStorage. Thus, I wrote a quick function that helps you setState automatically after the data is obtained from AS and there's also no need to parse the array of arrays given back by AsyncStorage.

var ls = require('react-native-local-storage');

lsSet(key, val){
  this.setState({[key]: val});
}

var n = ls.save('name', 'Kobe Bryant');
var a = ls.save('age', 37);
var pn = ls.save('player no.', 24);
Promise.all([n, a, pn]).then(()=>{
  ls.getSet(['name', 'age', 'player no.'], this.lsSet.bind(this))
    .then(()=>{
      console.log(this.state);
      // output should be "{name: "Kobe Bryant", age: 37, player no.: 24}"
    })
});

Storing multiple keys & values

console.log("test for saving an array of objects");

ls.save(['testArray', 'testingArray'], [
{
  blah1: 1,
  blah2: 2,
  blah3: 'numberrrr 3'
},
{
  blah4: 4,
  blah5: 5,
  blah6: 'numberrrr 6'
}
])
.then(() => {
  ls.getSet(['testArray', 'testingArray'], this.lsSet.bind(this))
    .then(()=>{
      console.log(this.state);
      // output should be "Object {testArray: Object, testingArray: Object}"
    })
})

Features to be implemented

  • [ ] Expand functionalities - neverending process ain't it?
  • [x] Implement setState feature
  • [x] Implement array feature
  • [ ] Implement fetch feature
  • [ ] Implement encryption feature
  • [ ] Implement cache+expiration feature
  • [ ] Implement tests using Jest

Contributors