skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    I have used an online page visit counter using https://www.hitwebcounter.com/webcounter.php


  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search