How to use the react-native.AsyncStorage.setItem function in react-native

To help you get started, we’ve selected a few react-native examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github N3TC4T / Nearby-Live / src / redux / core / user / actions.js View on Github external
}).then(async(res) => {
                if (!res.IsSuccess) {
                    return reject(new Error('Cant login with facebook right now!'));
                }

                // Set token in AsyncStorage + memory
                await AsyncStorage.setItem('api/token', res.Token);

                // Get user details from API, using user token
                return AppAPI.connect.get()
                    .then(async(userData) => {
                        dispatch({
                            type: 'USER_REPLACE',
                            data: userData
                        });
                        return resolve(userData);
                    }).catch(err => reject(err));
            }).catch(err => reject(err));
        } else {
github react-native-training / fundamentals-materials / src / containers / CrossPlatformAPIs / AsyncStorageExample.js View on Github external
storeData = () => {
    AsyncStorage.setItem(STORAGE_KEY, DATA)
      .then(() => {
        console.log('data stored..');
      });
  }
github crowdbotics / react-native-expo-scaffold / {{cookiecutter.project_slug}} / frontend / src / utils / api / utils.js View on Github external
setAccessToken: async (token) => {
    AsyncStorage.setItem(Constants.IDENTIFIERS.ACCESS_TOKEN, token);
  },
github CMP-Studio / DawnChorus / app / actions / alarm.js View on Github external
alarm.notificationTime = scheduleAlarm(alarm);
          } else {
            alarm.on = false;
            alarm.notificationTime = null;
          }
        }
        return alarm;
      });
    }

    if (activeAlarm === null) {
      SplashScreen.hide();
    }

    try {
      AsyncStorage.setItem('alarms', JSON.stringify(alarms));
      return dispatch(loadAlarmsSuccess(alarms, activeAlarm));
    } catch (error) {
      return null;
    }
  };
}
github hack4impact-uiuc / safe-maps / c2tc-mobile / screens / NotificationScreen.js View on Github external
}
    if (stateVar === "healthTips") {
      if (!this.state.healthTips) {
        await AsyncStorage.setItem("health_tips", "true");
        this.setState({ healthTips: !this.state.healthTips });
      } else {
        await AsyncStorage.setItem("health_tips", "false");
        this.setState({ healthTips: !this.state.healthTips });
      }
    }
    if (stateVar === "transpoTips") {
      if (!this.state.transpoTips) {
        await AsyncStorage.setItem("transpo_tips", "true");
        this.setState({ transpoTips: !this.state.transpoTips });
      } else {
        await AsyncStorage.setItem("transpo_tips", "false");
        this.setState({ transpoTips: !this.state.transpoTips });
      }
    }
    if (stateVar === "financialTips") {
      if (!this.state.financialTips) {
        await AsyncStorage.setItem("financial_tips", "true");
        this.setState({ financialTips: !this.state.financialTips });
      } else {
        await AsyncStorage.setItem("financial_tips", "false");
        this.setState({ financialTips: !this.state.financialTips });
      }
    }
  };
github syousif94 / frugalmaps / buncha / utils / User.js View on Github external
} else {
          localStorage[key] = json;
        }
      }
    } else {
      if (User.secureKeys.has(key)) {
        if (noValue) {
          SecureStore.deleteItemAsync(key);
        } else {
          SecureStore.setItemAsync(key, json);
        }
      } else if (User.persistedKeys.has(key)) {
        if (noValue) {
          AsyncStorage.removeItem(key);
        } else {
          AsyncStorage.setItem(key, json);
        }
      }
    }
  });
github mfrachet / rn-ab-hoc / src / reactNativeAbHoc.js View on Github external
async persistVariant({ variant, component }) {
      await AsyncStorage.setItem(`${LOCAL_STORAGE_KEY}-${experiment}`, variant);
      this.props.onVariantSelect(variant);
      return this.setState({ variant, component });
    }
github arthow4n / minimgur / src / minimgur.js View on Github external
saveState(callback) {
        AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(this.state), (err) => {
            if (err) {
                throw err;
            }
            if (callback) callback();
        });
    }
github wheatandcat / Peperomia / PeperomiaNative / src / containers / Auth.tsx View on Github external
const user = firebase.auth().currentUser;
    if (!user) {
      return null;
    }

    if (user.email) {
      await AsyncStorage.setItem('email', user.email);
      await AsyncStorage.setItem('uid', user.uid);
      setState({
        email: user.email,
        uid: user.uid,
      });
    }

    const idToken = await user.getIdToken(refresh);
    await AsyncStorage.setItem('id_token', idToken);
    await AsyncStorage.setItem(
      'expiration',
      String(new Date().getTime() + 60 * 60)
    );

    return idToken;
  }, []);
github lussatech / react-native-base-authentication / Login.js View on Github external
async onSuccess(data) {
    try {
      await AsyncStorage.setItem(key, JSON.stringify(data));
    } catch (error) {
      ToastAndroid.show(String(error).replace('Error: ',''), ToastAndroid.LONG);
    }
  }