jasonmerino / react-native-simple-store

A minimalistic wrapper around React Native's AsyncStorage.

Home Page:https://www.npmjs.com/package/react-native-simple-store

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do you check if a key: value already exists on a store?

Dcl1 opened this issue · comments

nvm solved it.

LOL thanks for not posting the solution for everyone else.

THANKS SHAUN! I actually realized a closer look at the original example shows how to check whether or not the .get returns a null. I believe. I didn't write anything because I thought it was obvious mistake, but I'll remember for the future.

To check to see if a key has a value associated with it, you would need to do something like this.

import store from 'react-native-simple-store';

store.get('key').then((value) => {
  if (value !== null) {
    // key exists
  } else {
    // key does not exist
  }
});

I'm working on an additional function on the simple store called keys which will get all keys in AsyncStorage but haven't been able to publish it yet. Hopefully soon.

Closing this issue since it's a question. Feel free to continue commenting if more help is needed.