TIL_51_230109

young0_0·2023년 1월 10일
0

TIL

목록 보기
50/91

51일 차 회고

  • 오타 에러!

에러

  • 로그인 하지 않았을때 로그인페이지로 이동하는 로직 에러
 useFocusEffect(
    useCallback(() => {
      if (!authService.currentUser) {
        reset({
          index: 1,
          routes: [
            {
              name: 'Tabs',
              params: {
                screen: 'Slide',
              },
            },
            {
              name: 'Stack',
              params: {
                screen: 'Login',
              },
            },
          ],
        });
        return;
      }

      setOptions({
        headerRight: () => {
          return (
            <TouchableOpacity style={{ marginRight: 10 }} onPress={logout}>
              <Text>로그아웃</Text>
            </TouchableOpacity>
          );
        },
      });

      const q = query(
        collection(dbService, 'profile'),
        orderBy('createdAt', 'desc'),
        where('userId', '==', authService.currentUser?.uid)
      );
      onSnapshot(q, (snapshot) => {
        const newProfiles = snapshot.docs.map((doc) => {
          const newProfile = {
            id: doc.id,
            ...doc.data(),
          };
          return newProfile;
        });
        setProfile(newProfiles);
      });
    }, [])
  );
  const profileFirst = profile[0];

에러해결

  • authService.currentUser 를 콘솔로 찍었을때 로그인 되면 확인이 가능하지만 그래도 비로그인 되지 않았을때 로그인 페이지로 이동 되지 않았다. 몇시간을 고민하였지만 찾지 못하였다.
const Root = () => {
  return (
    <Stack.Navigator
      screenOptions={{
        headerShown: false,
      }}
    >
      <Stack.Screen name="Tabs" component={Tabs} />
      <Stack.Screen name="Stacks" component={Stacks} />
    </Stack.Navigator>
  );
};

export default Root;
  • navigation Stack의 name의 s가 빠졌다..
    name: 'Stack' -> <Stack.Screen name="Stacks" component={Stacks} />

느낀점

뭐든 오타로 고생하지말자..

profile
열심히 즐기자ㅏㅏㅏㅏㅏㅏㅏ😎

0개의 댓글