React useEffect вызывает ошибку "create is not a function"
Sep 08 2020
У меня есть следующий модуль 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).
Я проверил этот вопрос , но уже занимаюсь им.
Ответы
Ozone Sep 08 2020 at 20:46
Возможно, вам придется использовать useStateвместо useEffect.
Видеть https://github.com/facebook/react/issues/15194 чтобы понять, почему эта ошибка отображается именно так.