const [myPhotos, setMyPhotos] = useState([]);
let token = localStorage.getItem('token');
const axiosConfig = {
headers: {
"Content-type": "application/json",
"responseType": "json",
"Authorization": token
},
};
useEffect(() => {
axios.get('http://localhost:5050/mypost', axiosConfig)
.then((res) => {
console.log(res.data)
setMyPhotos(res.data)
console.log(myPhotos)
})
.catch((e) => {
console.log(e)
});
}, []);
I am getting array of objects in res.data
but myPhotos is not updating after setMyPhotos(res.data)
. Can anyone please help me?