Sometimes, we want to fix Uncaught TypeError: this.props.data.map is not a function with React.
In this article, we’ll look at how to fix Uncaught TypeError: this.props.data.map is not a function with React.
How to fix Uncaught TypeError: this.props.data.map is not a function with React?
To fix Uncaught TypeError: this.props.data.map is not a function with React, we can check if this.props.data
is an array.
For instance, we write
{
Array.isArray(this.props.data) &&
this.props.data.map((e) => {
//...
});
}
to call Array.isArray
to check if this.props.data
is an array.
If it is, then we call this.props.data.map
to render the items from the data
entries.
Conclusion
To fix Uncaught TypeError: this.props.data.map is not a function with React, we can check if this.props.data
is an array.