I was creating a snapchat like web app and this is the chats page where all different snaps were commoing from different users, but when I open their snap their image is not rendering and I'm always ending with 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. at Chats
import "./Chats.css";
import { Avatar } from "@material-ui/core";
import SearchIcon from "@material-ui/icons/Search";
import ChatBubbleIcon from "@material-ui/icons/ChatBubble";
import { auth, db } from "./firebase";
import Chat from "./Chat";
import { useDispatch, useSelector } from "react-redux";
import { selectUser } from "./features/appSlice";
import RadioButtonUncheckedIcon from "@material-ui/icons/RadioButtonUnchecked";
import { useHistory } from "react-router";
import { resetCameraImage } from "./features/cameraSlice";
const Chats = () => {
const [posts, setPosts] = useState([]);
const user = useSelector(selectUser);
const dispatch = useDispatch();
const history = useHistory();
useEffect(() => {
db.collection("posts")
.orderBy("timestamp", "desc")
.onSnapshot((snapshot) =>
setPosts(
snapshot?.docs.map((doc) => ({
id: doc.id,
data: doc.data(),
}))
)
);
}, []);
const takeSnap = () => {
dispatch(resetCameraImage());
history.pushState("/");
};
return (
<div className="chats">
<div className="chats__header">
<Avatar
className="chats__avatar"
src={user.propilePic}
onClick={() => auth.signOut()}
/>
<div className="chats__search">
<SearchIcon className="chats__searchIcon" />
<input placeholder="Friends" type="text" />
</div>
<ChatBubbleIcon className="chats__chatIcon" />
</div>
<div className="chats__posts">
{posts.map(
({
id,
data: { profilePic, username, timestamp, imageUrl, read },
}) => (
<Chat
key={id}
id={id}
profilePic={profilePic}
username={username}
timestamp={timestamp}
imageUrl={imageUrl}
read={read}
/>
)
)}
</div>
<RadioButtonUncheckedIcon
className="chats_takePicIcon"
onClick={takeSnap}
fontSize="large"
/>
</div>
);
};
export default Chats;```