
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
1) 아래의 코드에서 remove(content.idx) 가 어떤 것을 지울지 타겟을 넘겨주는 것이라고 하셨고
const remove = async (cidx) 에서 그것을 받는다고 하셨습니다
여기서
content.idx 로 넘겨주었으면 cidx가 아닌 content.idx로 받아야 하는 것 아닌가요??
2) 지금 코드가 뭐가 뭔지도 잘 모르고 과제를 내주시면 어떻게 해야겠다는 생각이 드는데,
그걸 코드로 어떻게 표현해야 할지 모르겠습니다.
얘를 들어 remove 함수를 적용하기 위해 공식 문서를 봐도
이런 식으로 나와서 뭔 말인지도 모르겠네요;;
요는, 모르는 것은 답안 코드 보거나 튜터님께 물어보면서 그냥 계속 공부하면 될까요??
잘 배우고 있는 건지 걱정이 되어서 여쭤봅니다
<TouchableOpacity style={styles.button} onPress={()=>remove(content.idx)}><Text style={styles.buttonText}>찜 해제</Text></TouchableOpacity>
import React from 'react';
import {Alert,View, Image, Text, StyleSheet,TouchableOpacity,Platform} from 'react-native'
import {firebase_db} from "../firebaseConfig"
const isIOS = Platform.OS === 'ios';
import * as Application from 'expo-application';
//MainPage로 부터 navigation 속성을 전달받아 Card 컴포넌트 안에서 사용
export default function LikeCard({content,navigation,tip, setTip}){
const detail = () => {
navigation.navigate('DetailPage',{idx:content.idx})
}
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("삭제 완료");
let result = tip.filter((data,i)=>{
return data.idx !== cidx
})
console.log(result)
setTip(result)
})
}
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.buttonGroup}>
<TouchableOpacity style={styles.button} onPress={()=>detail()}><Text style={styles.buttonText}>자세히보기</Text></TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={()=>remove(content.idx)}><Text style={styles.buttonText}>찜 해제</Text></TouchableOpacity>
</View>
</View>
</View>
)
}
보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.
작성한 코드 및 에러 메세지
오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.
Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!
