출처
https://www.youtube.com/watch?v=1hPgQWbWmEk&t=10870s
오늘의 문제 사항은 3:53:00 부분에
if(props.following.indexOf( props.route.params.uid ) > -1 ){
setFollowing(true);
}else{
setFollowing(false);
}
이 부분이 이였다. 트루가 절대 안나온다.
많이 짜증이나 forech로 확인해봤다.
props.following.forEach(element => {
console.log(element)
console.log(props.route.params.uid)
});
{id: '6difKPatRIWJ7H9EDHe9UNtOicc2'}
So2pDRITizTJFvBrqBm7ol3FOW32
{id: '6difKPatRIWJ7H9EDHe9UNtOicc2'}
6difKPatRIWJ7H9EDHe9UNtOicc2
이렇게 나온다. 아 오브젝트랑 스트링이랑 달라서 그런가?
그런데 유툽에선 잘만된다...
그럼 오는 정보를 스트링에서 오브젝트로 바꾸면? 그럼 코드 수정이 너무 크다.
찾아보니 indexOf 와 비슷한것들이 있다.
참조 : https://bbaktaeho-95.tistory.com/40
여기 보니 find indexOf findIndex를 잘 설명해 주셧다.
보자보자 하니 이거 findIndex가 나한태 맞는 함수인거 같은데?
indexOf처럼 찾지 못하면 -1을 반환하고 찾으면 바로 종료해 낭비도 사라지고
적용했더니 바로 된다.
if(props.following.findIndex((e) => e.id === props.route.params.uid ) > -1 ){
setFollowing(true);
}else{
setFollowing(false);
}
감사합니다. ㅠㅠ 이걸로 10분 동안 로그를 뚫어져라 봤습니다.
'기록중' 카테고리의 다른 글
오늘의 클론코딩 (instargram) (0) | 2021.12.31 |
---|---|
오늘의 클론코딩 (instargram) (0) | 2021.12.30 |
오늘의 검색 코드 및 에러코드 (0) | 2021.12.27 |
오늘의 검색코드 및 오류코드 firebase v9 (0) | 2021.12.24 |
오늘만난 에러코드 검색코드(python pandas, fierbase v9) (0) | 2021.12.23 |