Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
카카오 도서 검색 API을 이용하여 책 찾기 기능을 만들었습니다.
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},
});
setBooks(response.data.documents);
} catch (error) {
console.error('Error fetching books:', error);
}
};
입력칸에 책 제목을 입력하면 카카오도서 검색 API를 호출하여서 책 데이터를 표시하는 것이다.
fetchBook 함수로 axios를 사용하여서 API 요청보낸다.
async을 이용하여 비동기적으로 책 데이터를 가져오는 것이다.
그리고 error가 발생했을 시 error 가 생겼다고 콘솔에 표시하도록 하였다.
https://developers.kakao.com/docs/latest/ko/daum-search/dev-guide에 있는 헤더들을 참고하면서 계속해서 코드 짜는 것이 처음이라 어려움이 느껴졌다.
그리고 처음 API에 대한 접근이 어려워 https://deep-wide-studio.tistory.com/202 를 참고하였습니다.