Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10회차 과제 - 권예원 #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions ass10/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

$ echo "apikey.js" >> .gitignore
$ cat .gitignore
apikey.js
28 changes: 28 additions & 0 deletions ass10/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.App {
font-family: sans-serif;
text-align: center;
}

input {
margin: 10px;
padding: 5px;
}

button {
padding: 5px 10px;
}

ul {
list-style-type: none;
padding: 0;
}

li {
margin: 10px 0;
}

img {
max-width: 100px;
}


16 changes: 16 additions & 0 deletions ass10/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import './App.css';
import BookSearch from './components/BookSearch';

function App() {
return (
<div className="App">
<h1>책 찾기</h1>
<BookSearch />
</div>
);
}

export default App;


21 changes: 21 additions & 0 deletions ass10/src/components/BookList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

const BookList = ({ books }) => {
if (!books.length) {
return <div>No books found</div>;
}

return (
<ul>
{books.map((book) => (
<li key={book.isbn}>
<h2>{book.title}</h2>
<p>{book.authors.join(', ')}</p>
<img src={book.thumbnail} alt={book.title} />
</li>
))}
</ul>
);
};

export default BookList;
38 changes: 38 additions & 0 deletions ass10/src/components/BookSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useState } from 'react';
import axios from 'axios';
import BookList from './BookList';
import API_KEY from "./apikey";




const BookSearch = () => {
const [books, setBooks] = useState([]);
const [query, setQuery] = useState('');

const fetchBooks = async () => {
try {
const response = await axios.get('https://dapi.kakao.com/v3/search/book?target=title', {
params: { query },
headers:{Authorization: API_KEY},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers: { Authorization: API_KEY } 를 이렇게 사용하는군요!
덕분에 알아갑니다:)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵넵 저도 살짝 헷갈리는 부분이 있어서 구글링하면서 진행하였습니다! 도움이 되셨다니 정말 기쁩니당:)

});
setBooks(response.data.documents);
} catch (error) {
console.error('Error fetching books:', error);
}
};

return (
<div>
<input
type="text"
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
<button onClick={fetchBooks}>Search</button>
<BookList books={books} />
</div>
);
};

export default BookSearch;
12 changes: 12 additions & 0 deletions ass10/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const rootElement = document.getElementById('root');
const root = ReactDOM.createRoot(rootElement);

root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);