import { useEffect, useState } from 'react';
import { type Book } from './Book';

const BooksList: React.FC = () => {
  const [books, setBooks] = useState<Book[]>([]);

  useEffect(() => {
    fetch('books/')
      .then((response) => response.json())
      .then((data) => setBooks(data));
  }, []);

  return (
    <ul>
      {books.map((book) => (
        <li key={book.id} data-testid="book">
          {book.title}
        </li>
      ))}
    </ul>
  );
};

export default BooksList;
