Skip to content

Instantly share code, notes, and snippets.

@benkeen
Last active August 29, 2015 14:19
Show Gist options
  • Save benkeen/c68c0635d3be672482ef to your computer and use it in GitHub Desktop.
Save benkeen/c68c0635d3be672482ef to your computer and use it in GitHub Desktop.
Overriding React Components
var Table = React.createClass({
getRows: function () {
return _.map(this.props.rows, function (row, i) {
return <TableRow key={i} row={row} />
});
},
render: function () {
return (
<table>
<thead>
<TableHeader />
</thead>
<tbody>
{this.getRows()}
</tbody>
</table>
);
}
});
var TableHeader = React.createClass({
render: function () {
return (
<tr>
<th>Col 1</th>
<th>Col 2</th>
</tr>
);
}
});
var TableRow = function () {
render: function () {
return (
<tr>
<td>{this.props.row.col1}</td>
<td>
{this.props.row.col1}
<Tooltip text={this.props.row.desc} />
</td>
</tr>
);
}
};
var Tooltip = React.createClass({
render: function () {
return (
<div className="tt">{this.props.text}</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment