I have a home page where whenever a user visits, I want to know how many times it has been visited till date. Now I dont required to save the count on local storage but in database or persistent storage.
You can have a useEffect with empty dependency array (implementing the componentOnMount). Then make your api call to the database in the useEffect.
Something like this:
useEffect(() => {
db.collection("posts")
.doc(postId)
.update({
views: increment,
});
}, []);
See this answer
3
I have used an online page visit counter using https://www.hitwebcounter.com/webcounter.php