# Resolved: Vidly Project Getting TypeError: Cannot read property 'map' of undefined

**URL:** <https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834>\
**Category:** React\
**Created:** [January 11, 2021, 11:07am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834 "2021-01-11T11:07:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumitb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sumitb/32/602_2.png) [@sumitb](https://forum.codewithmosh.com/u/sumitb)\
**Post date:** [January 11, 2021, 11:07am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/1 "2021-01-11T11:07:06Z")

</div>

Resolved: forgot to add props columns.

I was creating component tableBody, code is similar to what mosh has shown. Still I am getting the above error.

```
import React, { Component } from 'react';
import _ from 'lodash';

class TableBody extends Component {

    render() { 
        const { data, columns } = this.props;
        
        return ( 
            <tbody>
                {data.map( item => <tr>
                    { columns.map(column=>
                        <td>{_.get(item, column.path)} </td>
                        ) }
                </tr>)}

            </tbody>
         );
    }
}

```

export default TableBody;

---

<div class="post-metadata">

**Author:** ![Spark](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@Spark](https://forum.codewithmosh.com/u/Spark)\
**Post date:** [January 11, 2021, 11:26am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/2 "2021-01-11T11:26:42Z")

</div>

Could you log the data and columns variables to the console so we can see exactly what data and it’s type that the variables are storing ?

```
console.log(data,map);

```

Include the above line just below the  
`const {data, columns}`  
line and reload the app.

Then on your browser, press Ctrl+Shift+I, select the console tab, and post a screenshot of it here.

---

<div class="post-metadata">

**Author:** ![sumitb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sumitb/32/602_2.png) [@sumitb](https://forum.codewithmosh.com/u/sumitb)\
**Post date:** [January 11, 2021, 11:35am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/3 "2021-01-11T11:35:44Z")

</div>

Got the problem. Resolved.  
I have forgot to add props (columns) to component.  
It’s working now

---

<div class="post-metadata">

**Author:** ![sumitb](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sumitb/32/602_2.png) [@sumitb](https://forum.codewithmosh.com/u/sumitb)\
**Post date:** [January 11, 2021, 11:36am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/4 "2021-01-11T11:36:23Z")

</div>

Thanks for helping out

---

<div class="post-metadata">

**Author:** ![Augustine\_Awuori](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/augustine_awuori/32/873_2.png) [@Augustine\_Awuori](https://forum.codewithmosh.com/u/Augustine_Awuori)\
**Post date:** [February 6, 2021, 5:15pm UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/5 "2021-02-06T17:15:52Z")

</div>

Map is a method that only works with arrays. It means whatever you are chaining with the map method isn’t an array

---

<div class="post-metadata">

**Author:** ![DrDOMinance](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@DrDOMinance](https://forum.codewithmosh.com/u/DrDOMinance)\
**Post date:** [February 9, 2021, 11:16am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/6 "2021-02-09T11:16:02Z")

</div>

{\_.get(item, column.path)}

i’m getting error in this line

Error: Objects are not valid as a React child (found: object with keys {\_id, name}). If you meant to render a collection of children, use an array instead.

i did everything and follow every step as mosh but unable to find why i’m getting this error

for reference this is my stackoverflow post regarding the same topic.

[https://stackoverflow.com/questions/66106451/reactjs-tablebody-jsx-component-error-objects-are-not-valid-as-a-react-child](https://stackoverflow.com/questions/66106451/reactjs-tablebody-jsx-component-error-objects-are-not-valid-as-a-react-child)

---

<div class="post-metadata">

**Author:** ![tanveer19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/tanveer19/32/2046_2.png) [@tanveer19](https://forum.codewithmosh.com/u/tanveer19)\
**Post date:** [August 1, 2021, 6:37am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/7 "2021-08-01T06:37:56Z")

</div>

I am having the same problem I can’t understand how you solved the problem.  
can you please paste your code here?

---

<div class="post-metadata">

**Author:** ![William\_Wong](https://avatars.discourse-cdn.com/v4/letter/w/aca169/32.png) [@William\_Wong](https://forum.codewithmosh.com/u/William_Wong)\
**Post date:** [November 4, 2022, 12:19am UTC](https://forum.codewithmosh.com/t/resolved-vidly-project-getting-typeerror-cannot-read-property-map-of-undefined/1834/8 "2022-11-04T00:19:10Z")

</div>

I had the same error. I solved this by making this change in moviesTable.jsx:  
Line 25 Original : `<Tablebody data={movies} />`

Line25 Change to:`<Tablebody data={movies} columns={this.columns} />`

Reason for the error is because columns was not passed to props.  
Columns is undefined during map in movieBody.jsx even if

```auto
const { data, columns } = this.props // This is in movieBody.jsx

```

I think the problem is that props in movieBody.jsx still did not have the columns property so columns is still undefined. With the change in line 25 in movieTables.jsx, this is resolved.

Hope this helps.
