我想獲得 {book.volumeInfo.description} 元素的長度來檢查描述是否為空(如果 {book.volumeInfo.description} >0 {...} else { "Book without description"}我不知道如何以適當的方式獲得此 {book.volumeInfo.description} 元素的長度。你有什么理由來解決這個問題嗎?應用程序.jsimport React, { useState } from "react";import ReactDOM from "react-dom";import axios from "axios";import 'bootstrap/dist/css/bootstrap.min.css';const App = () => {const [searchTerm, setSearchTerm] = useState("");const [books, setBooks] = useState({ items: [] });const onInputChange = e => { setSearchTerm(e.target.value);};let API_URL = 'https://www.googleapis.com/books/v1/volumes';const fetchBooks = async () => { const result = await axios.get(`${API_URL}?q=${searchTerm}`); setBooks(result.data);};const onSubmitHandler = e => { e.preventDefault(); fetchBooks();};return ( <section> <form onSubmit={onSubmitHandler}> <label> <span>Search for books</span> <input type="search" placeholder="microservice, restful design, etc.," value={searchTerm} onChange={onInputChange} /> <button type="submit">Search</button> </label> </form> <ul> {books.items.map((book, index) => { return ( <div> <div class="row"> <div class="col-12"> <center> <h5>{book.volumeInfo.title}</h5> </center> <center> <h5>{book.volumeInfo.categories} </h5></center> <center> <h5>{book.volumeInfo.authors} </h5></center> <center> <h5>{book.volumeInfo.language} </h5></center> <center> <h5> {book.volumeInfo.publishedDate}</h5></center> <center> <h5>
如何獲得反應返回元素的長度?
慕哥9229398
2021-09-30 10:25:21