I want to count view every time the user visits the page using react-router-dom and Firebase, I have this Code:
//useHistory is the react-router-dom dependency
const history = useHistory();
const handleClick = () => history.push('/post');
if(handleClick) {
db.collection("posts").doc(postId).update({
views: increment,
})
}
Its works But its give an Infinite Loop I tried useEffect Like:
useEffect(() => {
if(handleClick) {
db.collection("posts").doc(postId).update({
views: increment,
})
}
}, [handleClick])
and it still gave the infinite increments, is there a way to count views without running in this type of problem?