Skip to content

Commit b2fa5fd

Browse files
committed
Better renderLinks
1 parent 424f665 commit b2fa5fd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

client/src/components/book/List.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ class List extends Component {
3434
this.props.reset(this.props.eventSource);
3535
}
3636

37+
renderLinks = (type, items) => {
38+
if (Array.isArray(items)) {
39+
return items.map((item, i) => (
40+
<div key={i}>{this.renderLinks(type, item)}</div>
41+
));
42+
}
43+
44+
return (
45+
<Link to={`../${type}/show/${encodeURIComponent(items)}`}>{items}</Link>
46+
);
47+
};
48+
3749
render() {
3850
return (
3951
<div>
@@ -66,6 +78,7 @@ class List extends Component {
6678
<th>description</th>
6779
<th>author</th>
6880
<th>publicationDate</th>
81+
<th>reviews</th>
6982
<th colSpan={2} />
7083
</tr>
7184
</thead>
@@ -83,6 +96,7 @@ class List extends Component {
8396
<td>{item['description']}</td>
8497
<td>{item['author']}</td>
8598
<td>{item['publicationDate']}</td>
99+
<td>{this.renderLinks('reviews', item['reviews'])}</td>
86100
<td>
87101
<Link to={`show/${encodeURIComponent(item['@id'])}`}>
88102
<span className="fa fa-search" aria-hidden="true" />

0 commit comments

Comments
 (0)