question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What am I missing - Uncaught TypeError: Cannot read property 'map' of undefined

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

54reactions
clayne11commented, Mar 16, 2016

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:

const CountryList = ({countries = []}) => (
  <div>
    This is the country list: <br/>
    <ul>
      {countries.map((_id, country) => (
        <li key={_id}>
          <h3>{country}</h3>
        </li>
      ))}
    </ul>
  </div>
);
0reactions
ntinykumarcommented, Dec 5, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found