Cannot read property map of undefined что делать
× TypeError: Cannot read properties of undefined (reading ‘map’)
When I try to run this code it gives me this error:
× TypeError: Cannot read properties of undefined (reading ‘map’)
I don’t know why. I have tried possible means, but it didn’t work.
9 Answers 9
Given the error, I would guess that that property wasn’t passed to the component.
Also, the parameter of the map lambda is «products» too. Change it to «product», or it will fail.
If you want to map out the products array that you created outside of your components then just change its name as the array has the same name as the properties passed. If you want to use the products (from the property) then make sure that you’re passing the properties in the component.
It’s because you have taken the array «products» and the map item «products» by the same name. Change the map item to something else like «product»:
Make sure to pass the products properties into the Product component. Change this:
Why? Because you’re mapping an object (products) into a JSX element in your case which is the
next js getInitialProps error Cannot read property ‘map’ of undefined
I have an error that cannot read property ‘map’ of undefined TypeError I want show menus.name list after mapping menus. I don’t understand this error
This is my ssr-test.js code
Next is my db.json code
This is error code..
2 Answers 2
Firstly check of everything is OK with your fetch url and you request is working. Secondly you should extract you response data one lever deep, because you are assign an object instead of array of data.
I have been experiencing the same issue for past few days, from my experience what I think is that since there is a request to external sources in the getInitialProps() function, it returns an unresolved javascript object.
When we directly try to use the data inside the objects, it works. But .map() doesn’t work.
NOTE : When printing the data to the console:
After Expanding ( the blue ‘i’ represents that the data was evaluated after expanding ), hence we were unable to use it in .map()
TypeError: Cannot read property ‘map’ of undefined in react-redux
Im new to React and Redux and still kinda confused a little bit.
My goal is to render a bunch of json datas in the HTML by using GET request. I’m using react and redux to manage the state of the objects, but I believe my problem is that the data is not even there
I get the error in the component
TypeError: Cannot read property ‘map’ of undefined
Index reducer, where i combine everything
I believe why the data is not there is because i didn’t call the action? any help would be appreciated.
2 Answers 2
mapStateToProps takes the root state as an argument (your index reducer, which is also the root reducer), not your course reducer. As far as I can tell this is the structure of your store:
So to get the courses from that state, in your component:
Also, you might consider initialising the state of the course reducer with an empty array of courses, so if you have to render the component before the action is fired, you won’t get the error.
Finally, you’re not firing the action at all, so you will never actually get the courses, I assume you want them to be retrieved once the Course component is loaded, for that you can use the componentDidMount event in your component.
First of all, you need to map the action to a property of the component
Now call the onGetCourses property when the component mounts
Parsing error: Cannot read property ‘map’ of undefined on import when a function has an array return type #2446
Comments
mwiedmann commented Aug 31, 2020
Repro
Expected Result
I expected it not to fail.
Actual Result
Parsing error: Cannot read property ‘map’ of undefined
The text was updated successfully, but these errors were encountered:
bradzacher commented Aug 31, 2020 •
What version of our tooling are you using?
That section is part of our template for a reason.
As mentioned in the first comment in the template:
mwiedmann commented Aug 31, 2020
«@typescript-eslint/eslint-plugin»: «4.0.0»,
«@typescript-eslint/parser»: «4.0.0»,
«eslint»: «7.7.0»,
«typescript»: «4.0.2»,
bradzacher commented Aug 31, 2020 •
TS4.0 included a breaking change to their AST shape which we’ve properly handled since our v3.3.0 release.
If you’ve got v4 of our packages installed and you’re still seeing errors, likely you also have older version(s) of our tooling installed alongside the new versions, and your local tooling is using the older versions.
See discussion in: #2260
Packages like react-scripts (part of create react app) will depend on their own (older) versions of our packages. You will have to use resolutions to bypass.
mwiedmann commented Sep 1, 2020
Yes. Confirmed that we did have an older version of the parser being pulled in by another package. Terribly sorry about this. Working fine now.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Comments
genyded commented Mar 16, 2016
The text was updated successfully, but these errors were encountered:
clayne11 commented 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:
genyded commented Mar 16, 2016
Thanks. that gets past the error, but then the countries never load (or show Loading. like Komposer says they should). The same query works with getMeteorData, so I doubt it’s a data issue. Am I missing something else?
clayne11 commented Mar 16, 2016
If you want to show a loading component you have call onData with no arguments:
genyded commented Mar 16, 2016
genyded commented Mar 16, 2016
saddiqueasad1 commented Nov 15, 2018
import React, < Component >from ‘react’;
export default Conuters;
saddiqueasad1 commented Nov 15, 2018
same problem on map
jcrommar commented Mar 28, 2019
Thanks, definitely worked!
simranshikha commented May 7, 2019
my indexOf not increase data
programmer-krish commented Sep 10, 2019
Uncaught TypeError: Cannot read property ‘map’ of undefined
import React from ‘react’;
import < Row, Col >from ‘react-bootstrap’;
import WeatherCard from ‘./WeatherCard’;
export default WeatherList;
import React from ‘react’;
import ‘./App.css’;
import CitySelector from ‘./Component/CitySelector’;
import
import < Container >from ‘react-bootstrap’;
import useFetch from ‘./hooks/useFetch’;
import WeatherList from ‘./Component/WeatherList’;
const App = () => <
const < data, error, inProgress, setUrl >= useFetch();
const getContent = () => <
if (error) return
Error when fetching:Loading.
Tiruvengadam85 commented Feb 29, 2020
Iam also getting similar issue TypeError: Cannot read property ‘map’ of undefined react,
when I want to destructure an item array
return items.map(item => (
usama147 commented Jul 20, 2020
can someone please help