I'm trying to use the response returned by an Axios GET request for displaying it on my webpage. However, when I'm trying to store the response using the useState hook in a state variable, I'm not getting the API fetched data in my state variable.
I figure it has something to do with the async nature of Axios. Any help on how I can successfully store it in the state would greatly help. Thanks.
const [responseData, setResponseData] = useState('');
axios.get('/URL', {
params: {
ABC: 'abc',
XYZ: '150'
}
})
.then((response) => {
console.log(response);
setResponseData(response.data);
}, (error) => {
console.log(error);
})
console.log('ResponseData: ' + responseData);
