I m using the Facebook fixed data table from : https://github.com/facebook/fixed-data-table
So I'm trying to convert a ReactCreateClass component to a React Component using ES6, here is the React Class :
<link rel="stylesheet" type="text/css" href="dist/fixed-data-table.css" />
<script src="dist/fixed-data-table.js"></script>
<script type="text/jsx">
var Column = FixedDataTable.Column;
var Table = FixedDataTable.Table;
var Cell = FixedDataTable.Cell;
var FilterExample = React.createClass({
render() {
return (
<Table
rowHeight={50}
rowsCount={1}
width={5000}
height={5000}
headerHeight={50}>
<Column
header={<Cell>Col 1</Cell>}
cell={<Cell>Column 1 static content</Cell>}
width={2000}
/>
<Column
header={<Cell>Col 2</Cell>}
cell={<Cell>Column 2 static content</Cell>}
width={2000}
/>
</Table>
);
},
});
ReactDOM.render(
<FilterExample />,
document.getElementById('react')
);
</script>
And here the result using React ES6 :
import React from 'react';
import ReactDOM from 'react-dom';
import {Table, Column, Cell} from 'fixed-data-table';
var rows = [
['a1', 'b1', 'c1'],
['a2', 'b2', 'c2'],
['a3', 'b3', 'c3']
];
class DataTable extends React.Component{
// Get initial state from stores
constructor(props) {
super(props);
console.log("Datatable constructor");
this.rowGetter = this.rowGetter.bind(this);
}
rowGetter(rowIndex) {
return rows[rowIndex];
}
render() {
return (
<Table
rowHeight={50}
rowsCount={rows.length}
rowGetter={this.rowGetter}
width={100}
height={250}
headerHeight={50}>
<Column
label="Col 1"
width={300}
dataKey={0}
/>
<Column
label="Col 2 "
width={40}
dataKey={1}
/>
<Column
label="Col 3"
width={30}
dataKey={2}
/>
</Table>
);
}
}
export default DataTable;
It's working fine but I don't understand why I need to add rowGetter method and attribute in the React ES6 component with the bind method. If I need to convert other React Component from facebook or other to ES6 It will be very long and messy. Why I can't just copy and paste the render method from the ReactClass to the React Component in ES6 ?