Reactjs TypeError:Cannot read property “city” of undefined The Next CEO of Stack OverflowReactJS Two components communicatingReactJS - Does render get called any time “setState” is called?Correct modification of state arrays in ReactJSReact - uncaught TypeError: Cannot read property 'setState' of undefinedreactjs Cannot read property 'keys' of undefinedCannot read property 'map' of undefined (Next.js)Data structure for highlights of words in a string with JavaScriptWhy react show that components update but console not?Lodash templating to render a React component instead of [object Object]Why am I getting the error “'CSS3DObject' is not exported from 'three'”?
Can you teleport closer to a creature you are Frightened of?
Could a dragon use its wings to swim?
Does the Idaho Potato Commission associate potato skins with healthy eating?
How can the PCs determine if an item is a phylactery?
How to compactly explain secondary and tertiary characters without resorting to stereotypes?
Why did the Drakh emissary look so blurred in S04:E11 "Lines of Communication"?
Is it correct to say moon starry nights?
Man transported from Alternate World into ours by a Neutrino Detector
Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico
Why doesn't Shulchan Aruch include the laws of destroying fruit trees?
Avoiding the "not like other girls" trope?
Why does freezing point matter when picking cooler ice packs?
Find a path from s to t using as few red nodes as possible
Is a distribution that is normal, but highly skewed, considered Gaussian?
Is the offspring between a demon and a celestial possible? If so what is it called and is it in a book somewhere?
Prodigo = pro + ago?
What difference does it make matching a word with/without a trailing whitespace?
Calculating discount not working
Why do we say “un seul M” and not “une seule M” even though M is a “consonne”?
The sum of any ten consecutive numbers from a fibonacci sequence is divisible by 11
How seriously should I take size and weight limits of hand luggage?
Can this transistor (2n2222) take 6V on emitter-base? Am I reading datasheet incorrectly?
How to show a landlord what we have in savings?
How to unfasten electrical subpanel attached with ramset
Reactjs TypeError:Cannot read property “city” of undefined
The Next CEO of Stack OverflowReactJS Two components communicatingReactJS - Does render get called any time “setState” is called?Correct modification of state arrays in ReactJSReact - uncaught TypeError: Cannot read property 'setState' of undefinedreactjs Cannot read property 'keys' of undefinedCannot read property 'map' of undefined (Next.js)Data structure for highlights of words in a string with JavaScriptWhy react show that components update but console not?Lodash templating to render a React component instead of [object Object]Why am I getting the error “'CSS3DObject' is not exported from 'three'”?
i am both new user here and reactjs , i tried to make a basic tour site but get an error; I believe its because of mapping but i cant see what's wrong,
Here is error and codes:
Uncaught TypeError: Cannot read property 'city' of undefined
The above error occurred in the component:
in Tourlist (at App.js:9)
in div (at
Blockquote
App.js:7)
in App (at src/index.js:9)
Consider adding an error boundary to your tree to customize error
handling behavior.import React from "react"
>
import Tourdata from "./components/Tourdata"
import Tourlist from "./components/Tourlist.js"
class CityTour extends React.Component
state=mytours:Tourdata
render() const touring=this.state.mytours
return(
<section>
touring.map(item =>return <Tourlist key=item.id tourinfo=item/> )
</section>
)
export const Tourdata= [id:1,city:"NewYork",name:"New York museums tour",
img:"https://images.pexels.com/photos/313782/pexels-photo-313782.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium, numquam."
,id:2,city:"London",name:"London royal palace tour",
img:"https://images.pexels.com/photos/1837591/pexels-photo-1837591.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet, conse
ctetur adipisicing elit. Delectus reprehenderit veritatis, expedita reiciendis quia voluptatum."
,id:3,city:"Istanbul",name:"Istanbul with all aspects",img:"https://images.pexels.com/photos/1549326/pexels-photo-1549326.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium, at. Nam, voluptate assumenda!"
,id:4,city:"Sydney",name:"Sydney city coast tour",img:"https://images.pexels.com/photos/1872047/pexels-photo-1872047.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum excepturi omnis deleniti. Accusamus." ]
import React from "react"
import "./tourlist.scss"
class Tourlist extends React.Component
state=show:false
handleIcon=()=>this.setState(show:!this.state.show)
render()const city,name,img,info=this.props.tourinfo
return( <section>
<div className="img-containers">
<i className="fas fa-window-close fa-3x text-success"></i>
<img src=img alt="Countryview" />
</div>
<div className="tourinfo">
<h3>city</h3>
<h4>name</h4>
<i onClick=this.handleIcon className="fas fa-caret-square-down text-success"></i>
this.state.show && <p>info </p>
</div>
</section>
)
export default Tourlist
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist />
</div>
);
export default App;
reactjs typeerror
add a comment |
i am both new user here and reactjs , i tried to make a basic tour site but get an error; I believe its because of mapping but i cant see what's wrong,
Here is error and codes:
Uncaught TypeError: Cannot read property 'city' of undefined
The above error occurred in the component:
in Tourlist (at App.js:9)
in div (at
Blockquote
App.js:7)
in App (at src/index.js:9)
Consider adding an error boundary to your tree to customize error
handling behavior.import React from "react"
>
import Tourdata from "./components/Tourdata"
import Tourlist from "./components/Tourlist.js"
class CityTour extends React.Component
state=mytours:Tourdata
render() const touring=this.state.mytours
return(
<section>
touring.map(item =>return <Tourlist key=item.id tourinfo=item/> )
</section>
)
export const Tourdata= [id:1,city:"NewYork",name:"New York museums tour",
img:"https://images.pexels.com/photos/313782/pexels-photo-313782.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium, numquam."
,id:2,city:"London",name:"London royal palace tour",
img:"https://images.pexels.com/photos/1837591/pexels-photo-1837591.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet, conse
ctetur adipisicing elit. Delectus reprehenderit veritatis, expedita reiciendis quia voluptatum."
,id:3,city:"Istanbul",name:"Istanbul with all aspects",img:"https://images.pexels.com/photos/1549326/pexels-photo-1549326.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium, at. Nam, voluptate assumenda!"
,id:4,city:"Sydney",name:"Sydney city coast tour",img:"https://images.pexels.com/photos/1872047/pexels-photo-1872047.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum excepturi omnis deleniti. Accusamus." ]
import React from "react"
import "./tourlist.scss"
class Tourlist extends React.Component
state=show:false
handleIcon=()=>this.setState(show:!this.state.show)
render()const city,name,img,info=this.props.tourinfo
return( <section>
<div className="img-containers">
<i className="fas fa-window-close fa-3x text-success"></i>
<img src=img alt="Countryview" />
</div>
<div className="tourinfo">
<h3>city</h3>
<h4>name</h4>
<i onClick=this.handleIcon className="fas fa-caret-square-down text-success"></i>
this.state.show && <p>info </p>
</div>
</section>
)
export default Tourlist
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist />
</div>
);
export default App;
reactjs typeerror
add a comment |
i am both new user here and reactjs , i tried to make a basic tour site but get an error; I believe its because of mapping but i cant see what's wrong,
Here is error and codes:
Uncaught TypeError: Cannot read property 'city' of undefined
The above error occurred in the component:
in Tourlist (at App.js:9)
in div (at
Blockquote
App.js:7)
in App (at src/index.js:9)
Consider adding an error boundary to your tree to customize error
handling behavior.import React from "react"
>
import Tourdata from "./components/Tourdata"
import Tourlist from "./components/Tourlist.js"
class CityTour extends React.Component
state=mytours:Tourdata
render() const touring=this.state.mytours
return(
<section>
touring.map(item =>return <Tourlist key=item.id tourinfo=item/> )
</section>
)
export const Tourdata= [id:1,city:"NewYork",name:"New York museums tour",
img:"https://images.pexels.com/photos/313782/pexels-photo-313782.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium, numquam."
,id:2,city:"London",name:"London royal palace tour",
img:"https://images.pexels.com/photos/1837591/pexels-photo-1837591.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet, conse
ctetur adipisicing elit. Delectus reprehenderit veritatis, expedita reiciendis quia voluptatum."
,id:3,city:"Istanbul",name:"Istanbul with all aspects",img:"https://images.pexels.com/photos/1549326/pexels-photo-1549326.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium, at. Nam, voluptate assumenda!"
,id:4,city:"Sydney",name:"Sydney city coast tour",img:"https://images.pexels.com/photos/1872047/pexels-photo-1872047.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum excepturi omnis deleniti. Accusamus." ]
import React from "react"
import "./tourlist.scss"
class Tourlist extends React.Component
state=show:false
handleIcon=()=>this.setState(show:!this.state.show)
render()const city,name,img,info=this.props.tourinfo
return( <section>
<div className="img-containers">
<i className="fas fa-window-close fa-3x text-success"></i>
<img src=img alt="Countryview" />
</div>
<div className="tourinfo">
<h3>city</h3>
<h4>name</h4>
<i onClick=this.handleIcon className="fas fa-caret-square-down text-success"></i>
this.state.show && <p>info </p>
</div>
</section>
)
export default Tourlist
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist />
</div>
);
export default App;
reactjs typeerror
i am both new user here and reactjs , i tried to make a basic tour site but get an error; I believe its because of mapping but i cant see what's wrong,
Here is error and codes:
Uncaught TypeError: Cannot read property 'city' of undefined
The above error occurred in the component:
in Tourlist (at App.js:9)
in div (at
Blockquote
App.js:7)
in App (at src/index.js:9)
Consider adding an error boundary to your tree to customize error
handling behavior.import React from "react"
>
import Tourdata from "./components/Tourdata"
import Tourlist from "./components/Tourlist.js"
class CityTour extends React.Component
state=mytours:Tourdata
render() const touring=this.state.mytours
return(
<section>
touring.map(item =>return <Tourlist key=item.id tourinfo=item/> )
</section>
)
export const Tourdata= [id:1,city:"NewYork",name:"New York museums tour",
img:"https://images.pexels.com/photos/313782/pexels-photo-313782.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium, numquam."
,id:2,city:"London",name:"London royal palace tour",
img:"https://images.pexels.com/photos/1837591/pexels-photo-1837591.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet, conse
ctetur adipisicing elit. Delectus reprehenderit veritatis, expedita reiciendis quia voluptatum."
,id:3,city:"Istanbul",name:"Istanbul with all aspects",img:"https://images.pexels.com/photos/1549326/pexels-photo-1549326.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium, at. Nam, voluptate assumenda!"
,id:4,city:"Sydney",name:"Sydney city coast tour",img:"https://images.pexels.com/photos/1872047/pexels-photo-1872047.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
,info:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum excepturi omnis deleniti. Accusamus." ]
import React from "react"
import "./tourlist.scss"
class Tourlist extends React.Component
state=show:false
handleIcon=()=>this.setState(show:!this.state.show)
render()const city,name,img,info=this.props.tourinfo
return( <section>
<div className="img-containers">
<i className="fas fa-window-close fa-3x text-success"></i>
<img src=img alt="Countryview" />
</div>
<div className="tourinfo">
<h3>city</h3>
<h4>name</h4>
<i onClick=this.handleIcon className="fas fa-caret-square-down text-success"></i>
this.state.show && <p>info </p>
</div>
</section>
)
export default Tourlist
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist />
</div>
);
export default App;
reactjs typeerror
reactjs typeerror
edited Mar 21 at 21:32
Sara Inés Calderón
584713
584713
asked Mar 21 at 19:54
TolimaTolima
14
14
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you declared 2 Tourlist
on your code. As I understand, something is wrong with this block of code.
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
try importing CityTour
here instead of Tourlist
because as the error says city is undefined
means you haven't provided the proper props needed. And according to your code CityTour
is the component with mapped data component (Tourlist
), so CityTour
must be declared somewhere.
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
no problem :) .
– kcNeko
Mar 21 at 20:22
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288322%2freactjs-typeerrorcannot-read-property-city-of-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you declared 2 Tourlist
on your code. As I understand, something is wrong with this block of code.
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
try importing CityTour
here instead of Tourlist
because as the error says city is undefined
means you haven't provided the proper props needed. And according to your code CityTour
is the component with mapped data component (Tourlist
), so CityTour
must be declared somewhere.
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
no problem :) .
– kcNeko
Mar 21 at 20:22
add a comment |
you declared 2 Tourlist
on your code. As I understand, something is wrong with this block of code.
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
try importing CityTour
here instead of Tourlist
because as the error says city is undefined
means you haven't provided the proper props needed. And according to your code CityTour
is the component with mapped data component (Tourlist
), so CityTour
must be declared somewhere.
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
no problem :) .
– kcNeko
Mar 21 at 20:22
add a comment |
you declared 2 Tourlist
on your code. As I understand, something is wrong with this block of code.
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
try importing CityTour
here instead of Tourlist
because as the error says city is undefined
means you haven't provided the proper props needed. And according to your code CityTour
is the component with mapped data component (Tourlist
), so CityTour
must be declared somewhere.
you declared 2 Tourlist
on your code. As I understand, something is wrong with this block of code.
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
try importing CityTour
here instead of Tourlist
because as the error says city is undefined
means you haven't provided the proper props needed. And according to your code CityTour
is the component with mapped data component (Tourlist
), so CityTour
must be declared somewhere.
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
import React, Component from 'react';
import './App.css';
import Navbar from "./components/Navbar.js"
import Tourlist from "./components/Tourlist.js"
class App extends Component
render()
return (<div>
<Navbar />
<Tourlist /> //change to CityTour
</div>
);
export default App;
edited Mar 21 at 20:09
answered Mar 21 at 20:03
kcNekokcNeko
3761215
3761215
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
no problem :) .
– kcNeko
Mar 21 at 20:22
add a comment |
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
no problem :) .
– kcNeko
Mar 21 at 20:22
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
Thanks a lot you saved my next hours,Actually i expected that Tourlist is main file there, because it is getting main information from CityTour which mapping transferred to it.
– Tolima
Mar 21 at 20:13
no problem :) .
– kcNeko
Mar 21 at 20:22
no problem :) .
– kcNeko
Mar 21 at 20:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288322%2freactjs-typeerrorcannot-read-property-city-of-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown