Hi guys i am new to react js and It keeps on saying TypeError: Cannot read property 'map' of undefined in react.js, even tho its not undefined.
//my variables
const [musics, setMusics] = useState()
const [user, setUser] = useState(null)
const [pfp, setPfp] = useState(null)
const { params: { uID } } = match;
var userName;
var musicArray = [];
//use effect so it does not infinite loop
useEffect(()=>{ firebase.database().ref("users/"+uID+"/public/songs/").on("value", (snapshot)=>{
var music = snapshot.val()
//gets title of each songs
Object.values(music).forEach((value)=>{
musicArray.push(value.title)//pushes value to array
setMusics(musicArray)//sets that array to musics
})
})
}, [])
return(
.....
<div class = "music-content-container">
<div class = "music-box">
<div class = "user-musics">
<ul>
//says TypeError: Cannot read property 'map' of undefined even tho its defined
{musics.map((name)=>{
return <li>{name}</li>
})}
</ul>
</div>
</div>
</div>
</div>
.....
)
how do I fix this issue? is there any way to fix this?