Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
get array from single firestore document with ReactJs

I'm learning to use firebase and react. I have shared my firestore collection image. and my code for fetching the array from my document is given below.

This code is fetching the data from my firestore database and then storing the result in my watchlistMovies react state. when i try to log the react state or even data.data() it gives the desired result but when i try to map over the array or do something similar like logging watchlistMovies.myList[0].media_type it hits me with an error. i tried my best trying different things making it work but it breaks a thing or two in process.

I hope someone here will help me. Thank you in advance! : )

updated the code

const Watchlist = () => {

    const [watchlistMovies, setwatchlistMovies] = useState([]);
    const {currentUser} = useAuth()
    const usersCollectionRef = collection(db,"users")
    const docRef = doc(db,"users",currentUser.uid)
    
    useEffect(() => {
        const getWatchListMovies = async () => {
            const data = await getDoc(docRef)
            if (data.exists()) {
                console.log(data.data());
                setwatchlistMovies([...watchlistMovies ,data.data().myList])
            } else {
                console.log("empty");
            }
        }
        getWatchListMovies();
    }, [])
    
    console.log(watchlistMovies);

    // console.log(watchlistMovies.myList[0]);

    return (
        <div className="content-page-area">
            <h1 className="trending-text">  My Watchlist </h1>
           
            
            <Container className="watchlist-container">
            <hr/>


            {watchlistMovies.map(
            (item) => (
                <ListContent
                item_poster={item.poster_url}
                item_title={item.media_title}
                item_year={item.release_year}
                item_rating={item.media_rating}
                item_type={item.media_type}
                item_id={item.media_id}
                />
            )
            )}


            
            </Container>
            <br/>
            <br/>
            <br/>
        </div>
    )
}

export default Watchlist

this is the image of my firestore db

error image

added console.log images

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda