I'm getting this below warning in console when i run he code.
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
Here is my code:
const [userDetail, setUserDetail] = React.useState('');
const personalDetails = (user_id) => {
axios
.get(`http://localhost:3001/users/${user_id}`, { withCredentials: true })
.then((response) => {
const personalDetails = response.data;
setUserDetail(response.data);
})
.catch((error) => {
console.log(" error", error);
});
};
React.useEffect(() => {
if (user_id) {
personalDetails(user_id);
}
}, [user_id]);
If I remove useEffect call, this error disappears. What is wrong here?