Is there any way to store values other than strings with AsyncStorage? I want to store simple boolean values for example.
AsyncStorage.setItem(\'key\', \'ok\
I suggest you use react-native-easy-app, through which you can access AsyncStorage synchronously, and can also store and retrieve objects, strings or boolean data.
import { XStorage } from 'react-native-easy-app';
import { AsyncStorage } from 'react-native';
export const RNStorage = {// RNStorage : custom data store object
token: undefined, // string type
isShow: undefined, // bool type
userInfo: undefined, // object type
};
const initCallback = () => {
// From now on, you can write or read the variables in RNStorage synchronously
// equal to [console.log(await AsyncStorage.getItem('isShow'))]
console.log(RNStorage.isShow);
// equal to [ await AsyncStorage.setItem('token',TOKEN1343DN23IDD3PJ2DBF3==') ]
RNStorage.token = 'TOKEN1343DN23IDD3PJ2DBF3==';
// equal to [ await AsyncStorage.setItem('userInfo',JSON.stringify({ name:'rufeng', age:30})) ]
RNStorage.userInfo = {name: 'rufeng', age: 30};
};
XStorage.initStorage(RNStorage, AsyncStorage, initCallback);