What am I missing - Uncaught TypeError: Cannot read property 'map' of undefined
See original GitHub issueI have the following two files and when I put the <CountryList/> on any page I get an error: Uncaught TypeError: Cannot read property 'map' of undefined
- any ideas?
CountryContainer.jsx:
import {composeWithTracker} from 'react-komposer'
import CountryList from 'common/client/components/list/CountryList.jsx'
import Countries from 'common/collections/Countries'
function composer(props, onData) {
if (Meteor.subscribe('countries').ready()) {
const countries = Countries.find({}).fetch()
onData(null, {countries})
};
};
export default composeWithTracker(composer)(CountryList)
CountryList.jsx:
import React from 'react';
const CountryList = ({countries}) => (
<div>
This is the country list: <br/>
<ul>
{countries.map((_id, country) => (
<li key={_id}>
<h3>{country}</h3>
</li>
))}
</ul>
</div>
);
export default CountryList;
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Error : Cannot read property 'map' of undefined - Stack Overflow
The error "Cannot read property 'map' of undefined" will be encountered if there is an error ...
Read more >How to Prevent the TypeError: Cannot Read Property Map of ...
As a result, the TypeError Cannot read property 'map' of undefined is very common and one of the first errors that developers will...
Read more >Fix the "Cannot read property 'map' of undefined" Error in React
The variable you are trying to map over is undefined . It will probably eventually be an array, but due to the asynchronous...
Read more >How to Read React Errors (fix 'Cannot read property of ...
This error usually means you're trying to use .map on an array, but that array isn't defined yet. That's often because the array...
Read more >TypeError: Cannot read property 'map' of undefined - Projects
I'm working on Jammming project but I got stuck on step 34: “In the TrackList component, use the .map() method to render each...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When your if statement evaluates to false you don’t return any data thus countries is null. You cannot map over a null value. If you change your
CountryList
to have a default value it will work:I am using out of the box SPFX list form modern reach js webpart and it was running well earlier on the sharepoint site online. Suddently it has started showining error. “TypeError: Cannot read property ‘map’ of undefined”. can anyone tell me the fix of this ? Can git hub has updated there online libraries and this issues is causing error due to that. Git hub please fix the issues and get it work again.