Any request done to Asyncstorage returns "not a function".
Getting and setting data to storage
Added with yarn and followed with react-native link
import React, { useEffect } from "react";
import { ActivityIndicator, View, StyleSheet } from "react-native";
import AsyncStorage from "@react-native-community/async-storage";
import { useDispatch } from "react-redux";
import PropTypes from "prop-types";
import nodejs from "nodejs-mobile-react-native";
import Colors from "../constants/Colors";
import { authenticate } from "../store/actions/auth";
const StartupScreen = props => {
const dispatch = useDispatch();
useEffect(() => {
const tryLogin = async () => {
try {
const userData = await AsyncStorage.getItem("userData");
if (!userData) {
props.navigation.navigate("Auth");
return;
}
const transFormedData = JSON.parse(userData);
const { token, userId, userMail, expirationDate } = transFormedData;
const expirationDateObj = new Date(expirationDate);
if (expirationDateObj <= new Date() || !token || !userId) {
props.navigation.navigate("Auth");
return;
}
nodejs.start("main.js");
nodejs.channel.addListener(
"message",
msg => {
console.log("From node: " + msg);
},
this
);
props.navigation.navigate("App");
dispatch(authenticate(userId, userMail, token, expirationDate));
} catch (e) {
console.log(e.message);
}
};
tryLogin();
}, [dispatch]);
return (
<View style={styles.screen}>
<ActivityIndicator size='large' color={Colors.primary} />
</View>
);
};
const styles = StyleSheet.create({
screen: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
});
StartupScreen.propTypes = {
navigation: PropTypes.any,
};
export default StartupScreen;
_asyncStorage.default.getItem is not a function
D:\Local workspace\Projects\guide-share-native\node_modules\react-native\Libraries\YellowBox\YellowBox.js:67
Possible Unhandled Promise Rejection (id: 0):
TypeError: _asyncStorage.default.getItem is not a function
TypeError: _asyncStorage.default.getItem is not a function
at _callee$ (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:94777:71)
at tryCatch (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:41606:19)
at Generator.invoke [as _invoke] (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:41781:24)
at Generator.prototype.
at tryCatch (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:41606:19)
at invoke (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:41682:22)
at blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:41712:13
at tryCallTwo (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:45331:7)
at doResolve (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:45495:15)
at new Promise (blob:http://localhost:8081/7ca2b190-cd81-4c2d-ba0e-719903711db9:45354:5)
Same issue. TypeError: _asyncStorage.default.getItem is not a function.
"@react-native-community/async-storage": "^2.0.0-rc.0",
"react": "16.9.0",
"react-native": "0.61.5"
Fixed downgrading to 1.6.3
npm i @react-native-community/async-storage@^1.6.3
@RodolfoGS
Please try with the latest version now (1.7.3).
Simple @react-native-community/async-storage would work now.
Most helpful comment
Fixed downgrading to 1.6.3
npm i @react-native-community/async-storage@^1.6.3