I'm using a get request to get info about a post from the backend, I receive the data fine, it's just an object with some of the values being arrays. For example the imageRoutes property has an array value. I've saved the response object into my state, but when I try to access the array information using dot or bracket notation or try to use array methods like '.length', it just comes up as undefined? Why is this?
const [post, setPost] = useState({})
const [error, setError] = useState('')
useEffect(() => {
fetchData()
}, [])
console.log(post)
console.log(post.imageRoutes)
console.log(post.imageRoutes.length)
console.log(post.imageRoutes[0])
const fetchData = async () => {
await axios.post('/forums-post', {post_id: match.params.id})
.then(res => {
res.data.error ? setError(res.data.error) : setPost(res.data)
})
}