1

错误类型错误:未定义不是对象(评估 '_$$_REQUIRE(_dependencyMap[6], "@react-native-async-storage/async-storage").AsyncStorage.getItem')

此错误位于:在 App (at renderApplication.js:48) 在 RCTView (at View.js:32) 在 View (at AppContainer.js:106) 在 RCTView (at View.js:32) 在 View (at AppContainer.js:133) 在 AppContainer (在 renderApplication.js:41)

引用我的代码:`

import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import OnboardingScreen from './Component/Onboardingscreen';
import LoginScreen from './Component/Loginscreen';
import { AsyncStorage } from '@react-native-async-storage/async-storage';
import { useEffect } from 'react';
const AppStack = createStackNavigator();

 const App =() => {
     const [isFirstLaunch, setIsFirstLaunch,] = React.useState(null);

     useEffect(() => {
         AsyncStorage.getItem('alreadyLaunched').then(value => {
             if(value == null) {
                 AsyncStorage.setItem('alreadyLaunched','true');
                 setIsFirstLaunch(true);
             } else {
                 setIsFirstLaunch(false);
             }
         });
     }, []);
     
     if (isFirstLaunch == null) {
         return null;
     } else if ( isFirstLaunch == true ){
        return (
            <NavigationContainer>
                <AppStack.Navigator
                headerMode='none'
                >
                    <AppStack.Screen name="OnboardingScreen" component={OnboardingScreen}/>
                    <AppStack.Screen name='login' component={LoginScreen} />
                </AppStack.Navigator>
            </NavigationContainer>
        );
     } else {
    return  <LoginScreen />;
 }
}

export default App;

`

4

1 回答 1

0

文档中所示,AsyncStorage应作为默认导入而不是命名导入导入。

所以替换:

import { AsyncStorage } from '@react-native-async-storage/async-storage';

经过:

import AsyncStorage from '@react-native-async-storage/async-storage';
于 2021-09-30T13:35:46.500 回答