JS - console.log cookie on react codes

0 votes
167 views
added Apr 5, 2023 in React by lcjr First Warrant Officer (11,930 points)

To check whether the cookie exists or not, you can use console.log and check the value returned by Cookies.get(cookieName). If the cookie exists, it will return the value of the cookie, which in this case is the string "inStoClosed". If the cookie does not exist, it will return undefined.

useEffect(() => {
  console.log('Cookie value:', Cookies.get(cookieName)); // add this line
  const fetchFeaturedSTO = async () => {
    // rest of the code
  };
  // rest of the code
}, [state, area, cookieName]);

This will log the value of the cookie to the console every time the useEffect function is called. You can then open your browser's developer console and check whether the cookie value is logged or not.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...