React useEffect에서 '생성은 함수가 아닙니다'오류 발생

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 이 오류가 이러한 방식으로 표시되는 이유를 알려드립니다.