Outside my PlaylistsLinks component I initialize the folders
variable and then I run a Firebase function that iterates through all the folder names and pushes it to the folders
array.
My map function does not iterate through my folders
array even though I can console.log my array within my component. Is there a specific way I have to pass the array into the functional component in order to use map
?
import React, { useState, useEffect, useRef } from 'react';
import firebase from "firebase/app";
import storage from "firebase/storage";
import firebaseConfig from "../dropzone/config";
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}else {
firebase.app(); // if already initialized, use that one
}
let fb_storage = firebase.storage();
let storageRef = fb_storage.ref();
let rootRef = storageRef.root;
let folders = [];
rootRef.listAll().then(function(res) {
res.prefixes.forEach(function(folderRef) {
// console.log(folderRef.name)
folders.push(folderRef.name)
// All the prefixes under listRef.
// You may call listAll() recursively on them.
});
res.items.forEach(function(itemRef) {
// All the items under listRef.
// console.log(itemRef.name);
});
}).catch(function(error) {
// Uh-oh, an error occurred!
});
const PlayListLinks = () =>{
console.log(folders);
return(
<>
<ul>
{folders.map((folder, index) => {
return <li key={index}> {folder}</li>
})}
</ul>
</>
)
}
export default PlayListLinks