import React, { Component } from 'react'
export default class App extends Component {
render() {
const data = [
{'name': 'Education', 'number': 33},
{'name': 'Promotion', 'number': 10},
{'name': 'Events', 'number': 55 }
]
let tableTemplate;
function makeColumns(row) {
return <td>{row.name} {row.number}</td>
}
tableTemplate = data.map((row, i) => {
return <tr key={i}>{makeColumns(row)}</tr>
})
return (
<table>
<tbody>
{tableTemplate}
</tbody>
</table>
)
}
}
ES5 код ниже
import React, { Component } from 'react'
export default class App extends Component {
render() {
var data = [
{'name': 'Education', 'number': 33},
{'name': 'Promotion', 'number': 10},
{'name': 'Events', 'number': 55 }
];
var tableTemplate;
function makeColumns(row) {
return <td>{row.name} {row.number}</td>
}
tableTemplate = data.map(function(row, i) {
return <tr key={i}>{makeColumns(row)}</tr>
});
return (
<table>
<tbody>
{tableTemplate}
</tbody>
</table>
)
}
}