-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-jsx.js
39 lines (32 loc) · 1.06 KB
/
react-jsx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const e = React.createElement
function Car(props) {
return e('div', { className: 'car' }, [
e('img', { className: 'car__img', src: props.car.img, key: 'img' }),
e('span', { className: 'car__name', key: 'span1' }, props.car.name),
e('span',{ className: 'car__price', key: 'span2' }, props.car.price)
])
}
class App extends React.Component {
state = {
cars: [
{ name: 'BMW', price: '2000', img: 'http://lorempixel.com/200/200/' },
{ name: 'Audi', price: '1500', img: 'http://lorempixel.com/201/200/' },
{ name: 'Mersedes', price: '2500', img: 'http://lorempixel.com/199/200/' },
{ name: 'Jaguar', price: '3000', img: 'http://lorempixel.com/200/201/ '}
]
}
renderCars() {
return this.state.cars.map(car => {
return (
e(Car, {car: car, key: car.name + Math.random()})
)
})
}
render() {
return e('div', {className: 'app'}, e(
'div', {className: 'car-wrapper'}, this.renderCars()
))
}
}
const domContainer = document.querySelector('#root');
ReactDOM.render(e(App), domContainer);