i am try to get the data from the express server. i am getting the data perfectly if i print the data. but if i try to print the data.name or data._id than it's showing the undefine and same condition with the state (book.name or book._id).
here is the code
function GetBookData() {
const [book, setBook] = useState([]);
useEffect(() => {
async function getBook() {
const res = await axios.get("http://localhost:5000/books");
const data = res.data.data;
setBook(data);
// const params = useParams();
console.log(data.name)
}
getBook();
}, []);
how to access the value from the data