I'm trying to avoid users to get to certain pages if they are not logged in. If they try to access "citas" but they are not logged it, they are redirected to "login". The problem is that I'm getting this error.
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.
This is the "citas" code
const Citas = () => {
const { currentUser } = useContext(AuthContext);
const history = useHistory();
useEffect(() => {
const unsuscribe = database.collection('NegociosDev').onSnapshot(function () {
database.collection('NegociosDev').doc('Peluquerías').collection('Negocios').doc('PR01').collection('citas').where('CheckIn', '>=', startDate.toISOString().split('T')[0]).get()
.then(response => {
const fetchedCitas = [];
const fetchedIDs = [];
response.forEach(document => {
const fetchedCita = {
id: document.id,
...document.data()
};
const fetchedID = document.id;
fetchedIDs.push(fetchedID);
fetchedCitas.push(fetchedCita);
});
setCitas(fetchedCitas);
setIDs(fetchedIDs)
})
return () => unsuscribe();
});
if (!currentUser) {
return <Redirect to="/index" />;
}
return <div></div>;
};
It redirects to the login page, but I keep getting this error.