React useEffect 引发'create is not a function'错误



我有以下React Native模块:

import React, {useContext, useEffect} from 'react';
import {Image, StyleSheet} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import AuthContext from '../context/auth/authContext';
const Intro = () => {
const getLocalUser = async () => {
try {
const value = await AsyncStorage.getItem('user');
return value;
} catch (error) {
console.log(error);
}
};
const localUser = getLocalUser();
const {setUser} = useContext(AuthContext);

useEffect(() => {
setUser({localUser});
}, []);
return (
<Image
style={styles.image}
source={require('../static/logo_intro.png')}
/>
);
}
const styles = StyleSheet.create({
image: {
width: 430,
resizeMode: 'center',
paddingTop: 500
}
})
export default Intro;

这会引发以下错误:[Tue Sep 08 2020 15:00:47.220] ERROR TypeError: create is not a function. (In 'create()', 'create' is undefined)

我检查了这个问题,但我已经在做了。

可能需要使用useState而不是useEffect

请参阅https://github.com/facebook/react/issues/15194以了解为什么会以这种方式显示此错误。

相关内容

最新更新