firestore getting doc data issue

onSnapshot() is a kind of asynchronous Observable method. You need to check are data exist then assign to any thing you want.

.onSnapshot(snap => {
            if(snap.exists()) { // Some methods returns object with .exist value/function.
               setImages(snap.data())
            }
        });

onSnapshot(snapshoot: QuerySnapshot<DocumentData> | DocumentSnapshot<DocumentData> => ...) This is what you get depending on on what you wariong on you can get generic object of querysnapshot or DocumentSnapshot.

This method will trigger when data will change in database. It returns unsubscription which you can invoke and stop observing database changes.

const unsubscription = db.collection("homeBackground").doc("bg_img").onSnapshot(snap => ...);

// later in time
unsubscription() // this will stop invoke method above.