Search code examples
reactjsstrapi

Uncaught TypeError: data.map is not a function in React.JS


Uncaught TypeError: data.map is not a function in React.J i am getting this error i don't know whats wrong with the code please help.

{data && data.map((blog) => (
            <BlogLists key={blog.id} blog={blog.attributes} />
          ))}
data: Array(5)
0: {id: 1, attributes: {…}}
1: {id: 2, attributes: {…}}
2: {id: 3, attributes: {…}}
3: {id: 4, attributes: {…}}
4: {id: 5, attributes: {…}}
length: 5

Solution

  • Use Array.isArray(data) to check the data type. Probabbly the DOM might get the value as empty object which is causing the issue.