Last active
August 29, 2015 14:22
-
-
Save andris-silis/187bbcef2fffb84bdb70 to your computer and use it in GitHub Desktop.
ReactJS test of table rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Table component without shouldComponentUpdate | |
import React from 'react'; | |
import _ from 'underscore'; | |
export default React.createClass({ | |
getInitialState() { | |
return { | |
tableData: [] | |
}; | |
}, | |
componentWillMount() { | |
// Generate initial table data state | |
this.setState({ | |
tableData: _.range(0, 10).map(rowIndex => _.range(0, 10)) | |
}); | |
}, | |
onNewDataClick() { | |
var tableData = this.state.tableData.map(row => { | |
row[0] = Math.random(); | |
return row; | |
}); | |
this.setState({ | |
tableData: tableData | |
}); | |
}, | |
renderCellEl(content, index) { | |
return ( | |
<td key={index}>{content}</td> | |
); | |
}, | |
renderRowEl(contentList, index) { | |
return ( | |
<tr key={index}>{contentList.map(this.renderCellEl)}</tr> | |
); | |
}, | |
render() { | |
return ( | |
<div> | |
<table> | |
{this.state.tableData.map(this.renderRowEl)} | |
</table> | |
<button onClick={this.onNewDataClick}>New data plskthnxbye</button> | |
</div> | |
); | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0".0.0.0.$0.$0""set textContent""{"textContent":"0.40472540468908846"}" | |
1".0.0.0.$1.$0""set textContent""{"textContent":"0.4246360862161964"}" | |
2".0.0.0.$2.$0""set textContent""{"textContent":"0.038479496724903584"}" | |
3".0.0.0.$3.$0""set textContent""{"textContent":"0.6841884981840849"}" | |
4".0.0.0.$4.$0""set textContent""{"textContent":"0.6603023638017476"}" | |
5".0.0.0.$5.$0""set textContent""{"textContent":"0.28145029209554195"}" | |
6".0.0.0.$6.$0""set textContent""{"textContent":"0.695664837025106"}" | |
7".0.0.0.$7.$0""set textContent""{"textContent":"0.889470687834546"}" | |
8".0.0.0.$8.$0""set textContent""{"textContent":"0.251313682179898"}" | |
9".0.0.0.$9.$0""set textContent""{"textContent":"0.4046918931417167"}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment