Answer the question
In order to leave comments, you need to log in
Why can't I iterate over an array using map. TypeError: test.map is not a function?
I get data from firebase
via axios and I want to render it
The data comes to the render function as an array of objects
Here I put it in the console:
render() {
const test = this.props.users;
console.log('test', test);
return (
<div>
{
test.map(u => {
return <div key={u.id}>
<div>{u.fullName}</div>
</div>
})
}
</div>
)
}
render() {
const dataFromComponent = [
{id: 1, fullName: 'Max' },
{id: 2, fullName: 'Jordan' },
{id: 3, fullName: 'Gary' },
{id: 4, fullName: 'Oleg' }
]
return (
<div>
{
dataFromComponent.map(u => {
return <div key={u.id}>
<div>{u.fullName}</div>
</div>
})
}
</div>
)
}
if (!test.map ) {
console.log("props", {...this.props})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question