Search code examples
reactjsreact-nativetypeerrorstoring-data

TypeError: Undefined is not an object key store


I just wanted to add an RNSecureKeystore to my React Native project, but I always get the error message: "TypeError: undefined is not an object (evaluating _reactNativeSecureKeystore.default.set')". Error located at DrawerNavScreen.

Could it be a problem of the React Native version?

   import React, {Component} from 'react';
import {TextInput, TouchableHighlight, Modal, Button, Platform, StyleSheet, Text, View, Image} from 'react-native';
import {createStackNavigator, createDrawerNavigator} from 'react-navigation';
import RNSecureKeyStore, {ACCESSIBLE} from "react-native-secure-key-store";

   render(){

// For storing key
RNSecureKeyStore.set("key1", "value1", {accessible: ACCESSIBLE.WHEN_UNLOCKED})
  .then((res) => {
    console.log(res);
  }, (err) => {
    console.log(err);
  });

// For retrieving key 
RNSecureKeyStore.get("key1")
  .then((res) => {
    console.log(res);
  }, (err) => {
    console.log(err);
  });

// For removing key 
RNSecureKeyStore.remove("key1")
  .then((res) => {
    console.log(res);
  }, (err) => {
    console.log(err);
  });   

Solution

  • It looks like you RNSecureKeyStore is not available in the app. Have you successfully linked the libraries together? react-native-link should do that, otherwise it may have something to do with the RN version that you're using.