I am newly learning react, and this is my first go at using useEffect and understanding state. I'm calling an api to get info which is working as intended, and using useEffect to set the data I retrieve into a stateful variable. My issues are arising when I attempt to display this data. I'm receiving an error that I have an undefined property of "name". Clearly, I'm doing something amiss and would appreciate any input to lead me in the right direction. I've attched an image from my console showing the info from the api, I'm attempting to display the name and some other info later on. Cheers.
All code is within a function
const [authorKey, setAuthorKey] = useState("OL23919A");
const [authorData, setAuthorData] = useState();
useEffect(() => {
getAuthors(authorKey).then((data) => {
console.log(data);
setAuthorData(data);
console.log(authorKey);
});
}, [authorKey]);
within my function's return (this is where my issue lies - error states .name is undefined)
<Typography name ={authorData.name}></Typography>
as well to note, I'm setting the key of each author in the api using an onClick:
onClick={() => setAuthorKey(author.key)}
Am expecting to print out author name in the JSX