how to access array datat in class component react
import React, { Component } from 'react'
import './TourList.scss';
import Tour from '../Tour/Tour';
import { tourData } from './tourData'; //impoert array of data
export default class TourList extends Component {
state={
tours:tourData // store array of data in state
}
render() {
const {tours}=this.state // store state in variable
return (
<section className="toulist">
{tours.map(tour=>{ // using map method to destructure
return <Tour key={tour.id} tour={tour} />; //pass as props
})}
</section>
)
}
}
//----------------------------------------------------
//how to access props in class component
const {id,city}=this.props.tour//props
Also in JavaScript:
- how to convert array to string json
- how to check has class name in js?
- javascript online test
- javascript default function parameter value
- mongoose save return id
- spotify api error parsing json
- change background colour jquery
- js remove if
- hide_node example jstree
- jquery delay to call function
- javascript get the last element of json
- force click btn using jquery
- video recorder using webrtc and javascript
- .classList
- install node js on raspberry pi
- express mounting router
- javascript get current date and time
- canvas nodejs
- timestamp to unix time react
- angular trigger input change
- node get value from map
- start angular app server
- set placeholder javascript
- call javascript function after page load complete