-
Notifications
You must be signed in to change notification settings - Fork 0
Vehicles
JP Barbosa edited this page Apr 24, 2018
·
3 revisions
nano ./src/data/vehicles.js
export default {
vehicles: [
{
_id: 1,
make: { name: 'Fiat' },
model: { name: 'Punto' },
color: { name: 'Prata' },
photo: '',
},
{
_id: 2,
make: { name: 'Honda' },
model: { name: 'HR-V' },
color: { name: 'Marrom' },
photo: '',
},
{
_id: 3,
make: { name: 'Hyundai' },
model: { name: 'HB20' },
color: { name: 'Verde' },
photo: '',
},
],
};
nano ./src/components/VehiclesList.js
import React, { Component } from 'react';
import staticData from '../data/vehicles';
import Vehicle from './Vehicle';
class VehiclesList extends Component {
render() {
return (
<div className="VehiclesList">
{staticData.vehicles.map(vehicle => (
<Vehicle vehicle={vehicle} key={vehicle._id} />
))}
</div>
);
}
}
export default VehiclesList;
nano ./src/components/Vehicle.js
import React, { Component } from 'react';
class Vehicle extends Component {
render() {
const { make, model, color, photo } = this.props.vehicle;
const img = photo || 'http://via.placeholder.com/240x180';
return (
<div className="Vehicle">
<img src={img} alt={make.name} />
<div>
<b>{make.name} {model.name}</b>
</div>
<div>{color.name}</div>
</div>
);
}
}
export default Vehicle;
nano ./src/components/App.js
import React from 'react';
import logo from '../styles/logo.svg';
import '../styles/App.css';
+ import VehiclesList from './VehiclesList';
class App extends Component {
render() {
return (
<div>
<header>...</header>
+ <VehiclesList />
</div>
);
}
);
export default App;
open http://localhost:3000/