I have a Firebase DB with a React-Native project using Expo. I can get data from DB with no problem. The problem becomes when I try to do a nested Firebase query for a many to many relationship. Here's my piece of code:
    useEffect(() => {
        setUser(firebase.auth().currentUser);
    });
    useEffect(() => {
        if (user) {
            async function getCertificates() {
                await firebase
                    .database()
                    .ref("/user_fav")
                    .child(user.uid)
                    .on("value", (querySnapShot) => {
                        const cert = [];
                        const temp = [];
                        querySnapShot.forEach((item) => {
                            temp.push(item.key);
                            firebase
                                .database()
                                .ref("/certificates")
                                .child(item.key)
                                .on("value", (querySnapShot) => {
                                    cert.push({
                                        name: querySnapShot.val().name,
                                        description: querySnapShot.val()
                                            .description,
                                        years: querySnapShot.val().years,
                                        key: querySnapShot.val().key,
                                    });
                                });
                        });
                        setData(cert);
                        setLoading(false);
                    });
            }
            getCertificates();
        }
    }, []);
First of all, I get the user for UID. I make a query asking for the certificates of a particular user (success, temp array is filled). Then, I try to get the certificates but here's the problem.
The first time Expo renders the App, I can't see the certificates. The array is empty. When I save the document (and Expo re-render) then the certificates appears.
It's very weird and I don't know where the problem is.
Thank you very much.
 
    