Hi im trying to set a state in my fetch call, When I try to access the state it returns undefined. Im not sure why it does this can someone help?
var [articlearray, setArticle]= React.useState([]);
var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({headline: props.headline})
};
fet(options)
function fet(options){
fetch('/headlines', options).then(response => response.json()).then(data =>{
var newsData = data.newsArray
setArticle(newsData)
})
}
console.log(articlearray[0]);