커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4주차 마지막 과제에서 안풀려서 정답을 보고 작성중인데 오류가 납니다.
[왕초보] 나만의 수익성 앱, 앱개발 종합반 v5
4주차
북마크
방*희
댓글
5
추천
0
조회수
14
조회수
14
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


오류 메세지를 보니 tip.filter 부분에서 filter라는 object가 정의되지않았다는것 같은데 어떻게 해결해야하나요?



스파르타 즉문즉답




WARN  Possible Unhandled Promise Rejection (id: 13):
TypeError: undefined is not an object (evaluating 'tip.filter')


generatorResume@[native code]        
asyncGeneratorStep@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:21008:26
_next@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:21027:29
tryCallOne@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:25621:16
http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:25702:27
http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:26597:26
_callTimer@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:26516:17
_callReactNativeMicrotasksPass@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:26546:17      
callReactNativeMicrotasks@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:26709:44
__callReactNativeMicrotasks@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=f?p?platfor?platform=android&dev=true&hot=false:20130:15
flushedQueue@http://192.168.219.110:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false:19957:21
flushedQueue@[native code]callFunctionReturnFlushedQueue@[native code]


import React from 'react';
import {View, Image, Text, TouchableOpacity, StyleSheet, Alert} from 'react-native'
import * as Application from 'expo-application';
const isIOS = Platform.OS === 'ios';
import {firebase_db} from "../firebaseConfig";


export default function LikeCard({content,navigation, tip, setTip}){
const remove = async (cidx) => {
  let userUniqueId;
  if(isIOS){
  let iosId = await Application.getIosIdForVendorAsync();
      userUniqueId = iosId
  }else{
      userUniqueId = await Application.androidId
  }


  console.log(userUniqueId)
  firebase_db.ref('/like/'+userUniqueId+'/'+cidx)
    .remove()
    .then(function(){
      Alert.alert("찜을 해제하였습니다!!")
    })
    .catch(function(){
      Alert.alert("찜 해제에 실패하였습니다!"+ error.message),
      navigation.navigate('LikePage')
    })
      //내가 찝 해제 버튼을 누른 카드 idx를 가지고
      //찝페이지의 찜데이터를 조회해서
      //찜해제를 원하는 카드를 제외한 새로운 찜 데이터(리스트 형태!)를 만든다
      let result = tip.filter((data,i)=>{
        return data.idx !== cidx
      })
      //이렇게 만들었으면!
      //LikePage로 부터 넘겨 받은 tip(찜 상태 데이터)를
      //filter 함수로 새롭게 만든 찜 데이터를 구성한다!
      console.log(result)
      setTip(result)


      }
//MainPage로 부터 navigation 속성을 전달받아 Card 컴포넌트 안에서 사용


    return(
        //카드 자체가 버튼역할로써 누르게되면 상세페이지로 넘어가게끔 TouchableOpacity를 사용
        <View style={styles.card}>
            <Image style={styles.cardImage} source={{uri:content.image}}/>
            <View style={styles.cardText}>
                <Text style={styles.cardTitle} numberOfLines={1}>{content.title}</Text>
                <Text style={styles.cardDesc} numberOfLines={3}>{content.desc}</Text>
                <Text style={styles.cardDate}>{content.date}</Text>
                <View style={styles.buttonGroup2}>
                    <TouchableOpacity style={styles.button2} onPress={()=>{navigation.navigate('DetailPage',{idx:content.idx})}}><Text style={styles.buttonText2}>자세히보기</Text></TouchableOpacity>
                    <TouchableOpacity style={styles.button2} onPress={()=>{remove(content.idx)}}><Text style={styles.buttonText2}>찜 해제</Text></TouchableOpacity>
                </View>
            </View>
        </View>
    )
}



const styles = StyleSheet.create({
    buttonGroup2:{
      flexDirection:"row",
      margin:7
    },
    button2:{
      flex:1,
      borderColor:"#FF00DD",
      alignContent:'center',
      borderWidth:1,
      borderRadius:10,
      padding:15,
      margin:7
    },
    buttonText2:{
      color:"#FF00DD",
      alignSelf:'center'
    },
    card:{
      flex:1,
      flexDirection:"row",
      margin:10,
      borderBottomWidth:0.5,
      borderBottomColor:"#eee",
      paddingBottom:10
    },
    cardImage: {
      flex:1,
      width:100,
      height:100,
      borderRadius:10,
    },
    cardText: {
      flex:2,
      flexDirection:"column",
      marginLeft:10,
    },
    cardTitle: {
      fontSize:20,
      fontWeight:"700"
    },
    cardDesc: {
      fontSize:15
    },
    cardDate: {
      fontSize:10,
      color:"#A6A6A6",
    }
});
취소
 공유
취소
댓글 0
댓글 알림
나의얼굴