function Search(){
const [title, setTitle]=useState('');
const [book, setBook]=useState([]);
const onChange=(e)=> setTitle(e.target.value);
const headers= {};
const getBookList= async ()=>{
try{
const response=await axios.get(`https://dapi.kakao.com/v3/search/book?target=title&query=${title}`, {headers});
setBook(response.data.documents);
console.log(response.data.documents);
}catch(e){
console.log(e);
}
};
useEffect(()=>{
getBookList();
console.log(book);
},[]);
return (
<div>
<input value={title} onChange={onChange}></input>
<button onClick={getBookList}>push</button>
<div>{book[0]}</div>
</div>
);
}
export default Search;
response.data.documents holds data like photos:
However, the variable called book does not contain anything. book[0] outputs nothing. How can we process this data?

book[0]is undefined the first time the component renders, because you set the default state to be[]. You also won't see anything when youconsole.log(book)because that hasn't been reassigned at that point.