Skip to content

Commit cef82af

Browse files
committed
init - book component
1 parent 1846c60 commit cef82af

File tree

8 files changed

+66
-7
lines changed

8 files changed

+66
-7
lines changed
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
interface Props {
4+
title: string;
5+
}
6+
7+
const Book: React.FC<Props> = ({ title }) => <li>{title}</li>;
8+
9+
export default Book;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import Book from './book';
3+
4+
const dummyData = {
5+
books: [{ id: '1', title: 'Active Rails' }],
6+
};
7+
8+
const loading = false;
9+
10+
const Books = () => {
11+
if (loading) {
12+
return <span>Loading...</span>;
13+
}
14+
15+
return (
16+
<div>
17+
<h1>Books</h1>
18+
<ul>
19+
{dummyData.books.map((book) => (
20+
<Book {...book} key={book.id} />
21+
))}
22+
</ul>
23+
</div>
24+
);
25+
};
26+
27+
export default Books;

app/javascript/hello_react.jsx

-3
This file was deleted.

app/javascript/packs/application.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import mount from '../mount';
55
import "channels"
66

77
// React Components
8-
import Hello from "../hello_react"
8+
import Books from "../components/Book/book_container"
99

1010
Rails.start()
1111
Turbolinks.start()
1212
ActiveStorage.start()
1313

14-
mount({Hello})
14+
mount({Books})

app/views/home/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<h1>Home</h1>
2-
<%= react_component "Hello", { name: "Test" } %>
2+
<%= react_component "Books" %>

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"version": "0.1.0",
1919
"devDependencies": {
20+
"@types/react": "^17.0.39",
2021
"webpack-dev-server": "^3"
2122
}
2223
}

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"sourceMap": true,
1515
"target": "es5",
16-
"noEmit": true
16+
"noEmit": true,
17+
"allowSyntheticDefaultImports": true
1718
},
1819
"exclude": [
1920
"**/*.spec.ts",

yarn.lock

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)