access functions inside classes javascript code example
Example 1: 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';
export default class TourList extends Component {
state={
tours:tourData
}
render() {
const {tours}=this.state
return (
<section className="toulist">
{tours.map(tour=>{
return <Tour key={tour.id} tour={tour} />;
})}
</section>
)
}
}
const {id,city}=this.props.tour
Example 2: variables in js class
constructor(){
this.foo = bar
}