Я не могу отфильтровать ложные данные. Я не знаю, что я делаю неправильно. и нет ошибки. Всякий раз, когда я печатаю внутри панели поиска, вывод ничего не фильтрует. Я могу отображать содержимое mockData, но не могу фильтровать эти mockData.
class BookshelfChanger extends Component {
state = {
value: this.props.shelf
};
handleChange = event => {
this.setState({ value: event.target.value });
this.props.onMove(this.props.book, event.target.value);
};
render() {
return (
<div className="book-shelf-changer">
<select value={this.state.value} onChange={this.handleChange}>
<option value="move" disabled>
Move to...
</option>
<option value="currentlyReading">Currently Reading</option>
<option value="wantToRead">Want to Read</option>
<option value="read">Read</option>
<option value="none">None</option>
</select>
</div>
);
}
}
class SearchBooks extends Component {
render() {
const { books, onResetSearch, onSearch} = this.props;
console.log(books);
return (
<div className="search-books">
<SearchBar onSearch={onSearch} onResetSearch={onResetSearch} />
<SearchResults
books={books}
/>
</div>
);
}
}
const SearchBar = props => {
const {onSearch, onResetSearch } = props;
return (
<div className="search-books-bar">
<CloseSearchButton onResetSearch={onResetSearch} />
<SearchBooksInput onSearch={onSearch} />
</div>
);
};
const CloseSearchButton = props => {
const { onResetSearch } = props;
return (
<Link to="/">
<button className="close-search" onClick={onResetSearch}>
Close
</button>
</Link>
);
};
class SearchBooksInput extends Component {
state = {
value: '',
data:getAll
};
handleChange = event => {
const val = event.target.value;
this.setState({ value: val });
console.log(this.state.data)
};
render() {
const { value, data } = this.state;
// const lowercasedFilter = value.toLowerCase();
const filteredData = data.filter(book => {
return Object.keys(book)
});
console.log(filteredData)
return (
<div className="search-books-input-wrapper">
<input
type="text"
value={value}
placeholder="Search by title or author"
onChange={this.handleChange}
/>
{filteredData.map(book => (
<Book
key={book.id}
book={book}
shelf= 'none'
/>
))}
</div>
);
}
}
const SearchResults = props => {
const { books} = props;
// const booksOnThisShelf = books.filter(book => book.shelf === shelf);
return (
<div className="search-books-results">
<ol className="books-grid">
{books.map(book => (
<Book
key={book.id}
book={book}
shelf= 'none'
/>
))}
</ol>
</div>
);
};
Книга:
const Book = props => {
const { book, shelf, onMove } = props;
return (
<li>
<div className="book">
<div className="book-top">
<div
className="book-cover"
style={{
width: 128,
height: 193,
backgroundImage: `url(${book.imageLinks.thumbnail})`
}}
/>
<BookshelfChanger book={book} shelf={shelf} onMove={onMove} />
</div>
<div className="book-title">{book.title}</div>
<div className="book-authors">{book.authors}</div>
</div>
</li>
);
};
getAll (mockData):
const getAll = [
{
title: "the book of RA",
authors: ['Robert Galbraith'],
imageLinks: {
thumbnail:
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQK_a32ZoQ0mUQ8hHj0rS-ZXSoiA9ujpS1thED04xWG-l-G8bTB&usqp=CAU'
},
id: 'evuwdDLfAyYw',
shelf: 'wantToRead',
},
{
title: 'bahamut dragon god',
authors: ['Liaquat Ahamed'],
imageLinks: {
thumbnail:
'https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSPNgP0LX5_1psjQracNJGJ_qhuFcK_uyf9cumzjEV_9qOsBBi0&usqp=CAU'
},
id: '74XNzF_al3Mr',
shelf: 'wantToRead',
},
{
title: 'Needful Things',
authors: ['Stephen King'],
imageLinks: {
thumbnail:
'http://books.google.com/books/content?id=jAUODAAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api',
},
]
профиль gitHub
Выходное изображение показано здесь. ошибки нет, поэтому я не могу понять, в чем проблема