강의

멘토링

커뮤니티

Inflearn Community Q&A

oan63103756's profile image
oan63103756

asked

Learn React and Firebase by following along - Creating a Chat Application [Renewed in December 2023]

Favorite Button UI & Add Favorite Information to Database

안녕하세요 강사님

Written on

·

209

1

10: 26초쯤에  chatroom.id를 [] 이렇게 배열안에다가 넣는 이유가 있을까요? 처음보는 거라서 궁금합니다!!

else {
            usersRef
                .child(`${user.uid}/favorited`).update({
                   
                    [chatRoom.id]: {
                        name: chatRoom.name,
                        description: chatRoom.description,
                        createdBy: {
                            name: chatRoom.createdBy.name,
                            image: chatRoom.createdBy.image
                        }
                    }
               })
웹앱firebasereact

Answer 1

0

John Ahn님의 프로필 이미지
John Ahn
Instructor

안녕하세요 빠스단님 
이럴때 가장 쉽게 이해하는 법은  console을 찍어서 두개를 비교해보면 됩니다.

console.log('chatRoom.id', chatRoom.id)
console.log('[chatRoom.id]', [chatRoom.id])

그래서 이렇게 두개를 비교해 보면 하나는 그냥 텍스트이고 하나는 배열안에 들어가 있습니다. 

그리고 이렇게 배열을 사용하는 이유는 

favorited 안에 하나의 방정보만 들어가는게 아닌 여러가 들어가기 때문입니다. 

수고하세요 ~

oan63103756's profile image
oan63103756

asked

Ask a question